import java.util.Arrays; import java.util.Scanner; import java.util.concurrent.SynchronousQueue; class Main { int N, M; int[] X, Y; public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); String[] s = new String[N]; for (int i = 0; i < N; ++i) { s[i] = sc.next(); } long M = sc.nextLong(); long x = sc.nextLong(); long d = sc.nextLong(); long[] i_ = new long[(int) M]; long[] j_ = new long[(int) M]; for (int k = 0; k < M; ++k) { i_[k] = (x / (N - 1)) + 1; j_[k] = (x % (N - 1)) + 1; if (i_[k] > j_[k]) { long tmp = i_[k]; i_[k] = j_[k]; j_[k] = tmp; } else { j_[k] = j_[k] + 1; } x = (x + d) % (N * (N - 1)); } long p = 1_000_000_000 + 7; long[][] id = new long[N][]; for (int i = 0; i < N; ++i) { id[i] = new long[s[i].length()]; for (int j = 0; j < s[i].length(); ++j) { id[i][j] = (j - 1 >= 0 ? id[i][j - 1] : 0) * p + (s[i].charAt(j) - 'a'); } } int ans = 0; for (int k = 0; k < M; ++k) { int i = (int) (i_[k]) - 1; int j = (int) (j_[k]) - 1; int l = 0; int r = 1 + Math.min(s[i].length(), s[j].length()); while (r - l > 1) { int m = (l + r) / 2; if (id[i][m - 1] == id[j][m - 1]) { l = m; } else { r = m; } } ans += l; } System.out.println(ans); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }