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 p1 = 1_000_000_000 + 7; // long p2 = 1_000_00 + 9; long[][] id1 = new long[N][]; long[][] id2 = new long[N][]; for (int i = 0; i < N; ++i) { id1[i] = new long[s[i].length()]; // id2[i] = new long[s[i].length()]; for (int j = 0; j < s[i].length(); ++j) { id1[i][j] = (j - 1 >= 0 ? id1[i][j - 1] : 0) * p1 + (s[i].charAt(j) - 'a'); // id2[i][j] = (j - 1 >= 0 ? id2[i][j - 1] : 0) * p2 + // (s[i].charAt(j) - 'a'); id2[i][j] = (j - 1 >= 0 ? (id2[i][j - 1] << 1) : 0) + (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 (id1[i][m - 1] == id1[j][m - 1] && id2[i][m - 1] == id2[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)); } }