#include using namespace std; typedef long long LL; #define fin "\n" #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define DEBUG if(0) #define REC(ret, ...) std::function template inline bool chmin(T &l,T r) {bool a=l>r;if(a)l=r;return a;} template inline bool chmax(T &l,T r) {bool a=l istream& operator>>(istream &is,vector &v){ for(auto &it:v)is>>it; return is; } typedef unsigned long long ULL; typedef long long LL; const ULL h=937919; char str[912345]; int main(){ int N; scanf("%d",&N); vector s(N); vector> hh(N); REP(i,N){ scanf("%s",str); s[i]=str; hh[i].resize(s[i].size()+1); hh[i][0]=0; REP(j,s[i].size()){ hh[i][j+1]=hh[i][j]*h+s[i][j]; } } // return 0; LL x,d,M; scanf("%lld %lld %lld",&M,&x,&d); LL res=0; REP(q,M){ LL i = x/(N-1)+1; LL j = x%(N-1)+1; if(i>j)swap(i,j); else j++; i--,j--; int lb=0; int ub=min(s[i].size(),s[j].size())+1; while(ub-lb>1){ const int mid=(ub+lb)/2; if(hh[i][mid]==hh[j][mid])lb=mid; else ub=mid; } res+=lb; x=(x+d)%(N*(N-1ll)); } cout<