#include using namespace std; const int MAXN = int( 1e5 ); const int MAXLEN = int( 8e5 ); const int BASE = 311; const int MOD = int( 1e9 ) + 7; int N; string S[ MAXN ]; int pbase[ MAXLEN + 1 ]; vector< int > phash[ MAXN ]; long long M, X, D; pair< int, int > get_nxt() { int i = ( X / ( N - 1 ) ) + 1; int j = ( X % ( N - 1 ) ) + 1; if( i > j ) { swap( i, j ); } else { j = j + 1; } X = ( X + D ) % ( 1LL * N * ( N - 1 ) ); return make_pair( i - 1, j - 1 ); } int gh( int x, int lb, int rb ) { // [ lb, rb ) int res = ( phash[ x ][ rb ] - 1LL * phash[ x ][ lb ] * pbase[ rb - lb ] % MOD ) % MOD; if( res < 0 ) res += MOD; return res; } int get_lcp( int a, int b ) { int lb = 0, ub = min( S[ a ].size(), S[ b ].size() ) + 1; while( lb + 1 != ub ) { int mid = lb + ub >> 1; int ha = gh( a, 0, mid ); int hb = gh( b, 0, mid ); ( ha == hb ? lb : ub ) = mid; } return lb; } signed main() { for( int i = pbase[ 0 ] = 1; i <= MAXLEN; ++i ) { pbase[ i ] = 1LL * pbase[ i - 1 ] * BASE % MOD; } ios::sync_with_stdio( 0 ); cin >> N; for( int i = 0; i < N; ++i ) { cin >> S[ i ]; phash[ i ].assign( S[ i ].size() + 1, 0 ); for( int j = 0; j < S[ i ].size(); ++j ) { phash[ i ][ j + 1 ] = ( 1LL * phash[ i ][ j ] * BASE + S[ i ][ j ] ) % MOD; } } cin >> M >> X >> D; long long ans = 0; for( int qi = 0; qi < M; ++qi ) { int a, b; tie( a, b ) = get_nxt(); ans += get_lcp( a, b ); } cout << ans << endl; return 0; }