#include using namespace std; typedef long long ll; typedef pair P; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m, x, d; cin >> n; vector s(n); for (int i = 0; i < n; i++) cin >> s[i]; cin >> m >> x >> d; map memo; long long ans = 0; for (int k = 0; k < m; k++) { int i = x / (n - 1); int j = x % (n - 1); if (i > j) swap(j, i); else j++; int lmin = min(s[i].length(), s[j].length()); int tmp = lmin; for (int h = 0; h < lmin; h++) { if (s[i][h] != s[j][h]) { tmp = h; break; } } ans += tmp; x = (x + d) % (n * (n - 1)); } cout << ans << endl; return 0; }