#include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))< ostream& operator<<(ostream& o, const pair &p){o<<"("< ostream& operator<<(ostream& o, const vector &v){o<<"[";for(T t:v){o< hash1[100005], hash2[100005]; int sz[100005]; int main(){ cin.tie(0); ios::sync_with_stdio(false); long n; cin>>n; rep(i,n){ string s; cin>>s; sz[i] = s.size(); hash1[i].resize(sz[i]+1); hash2[i].resize(sz[i]+1); hash1[i][0] = 0; hash2[i][0] = 0; rep(j,sz[i]){ hash1[i][j+1] = hash1[i][j]*MOD + s[j]; // hash1[i][j+1] %= DOM; hash2[i][j+1] = hash2[i][j]*MOD + s[j]; // hash2[i][j+1] %= MMM; } } long m,x,d; cin>>m>>x>>d; long ans = 0; rep(_,m){ long i = (x/(n-1)); long j = (x%(n-1)); if(i<=j) j++; int l=0, r=min(sz[i], sz[j]); while(r-l>1){ int mid = (r+l)/2; if(hash1[i][mid]==hash1[j][mid] && hash2[i][mid]==hash2[j][mid]) l=mid; else r=mid; } ans += l; x = (x+d)%(n*(n-1)); } cout << ans << endl; return 0; }