#include using namespace std; const unsigned long long h = 1000000007; const unsigned long long h2 = 1000000009; const unsigned long long h3 = 1000000021; int main() { int n; cin >> n; vector s(n); vector> hh(n); for (int i = 0; i < n; i++) { cin >> s[i]; hh[i].resize(s[i].size() + 1); hh[i][0] = 0; for (int j = 0; j < s[i].size(); j++) { hh[i][j + 1] = hh[i][j] * h + s[i][j]; hh[i][j + 1] %= h2; hh[i][j + 1] = hh[i][j] * h + s[i][j]; hh[i][j + 1] %= h3; } } long long m, x, d; cin >> m >> x >> d; unsigned long long sum = 0; for (int k = 1; k <= m; k++) { int i, j; i = (x / (n - 1)); j = (x % (n - 1)); if (i > j) { swap(i, j); } else { j++; } x = (x + d) % (n * (n - 1)); int l = 0; int r = min(s[i].size(), s[j].size()) + 1; while (r - l > 1) { int mid = (l + r) / 2; if (hh[i][mid] == hh[j][mid]) { l = mid; } else { r = mid; } } sum += l; } cout << sum << endl; return 0; }