#include using namespace std; namespace { const int MAX_N = 100000; long long i[ MAX_N + 5 ]; long long j[ MAX_N + 5 ]; long long N; long long M; string S[ MAX_N + 5 ]; void SetArr( const int x0, const int d0 ) { int k; long long x; long long d; x = x0; d = d0; for( k = 1; k <= M; k++ ) { i[ k ] = ( x / ( N - 1 ) ) + 1; j[ k ] = ( x % ( N - 1 ) ) + 1; if( i[ k ] > j[ k ] ) swap( i[ k ], j[ k ] ); else j[ k ] += 1; x = ( x + d ) % ( N * ( N - 1 ) ); } } int Check( const string &lpA, const string &lpB ) //int Check( const char *lpA, const char *lpB ) { int i; i = 0; while( lpA[ i ] != '\0' && lpA[ i ] == lpB[ i ] ) i++; return i; } } // namespace int main( int argc, char *argv[] ) { int a; int x; int d; long long iSum; cin >> N; for( a = 1; a <= N; a++ ) cin >> S[ a ]; cin >> M; cin >> x; cin >> d; SetArr( x, d ); iSum = 0; for( a = 1; a <= M; a++ ) { iSum += Check( S[ i[ a ] ], S[ j[ a ] ] ); // iSum += Check( S[ i[ a ] ].c_str(), S[ j[ a ] ].c_str() ); } cout << iSum << endl; return 0; }