import sys def solve(): def ilog2(n): return 0 if n <= 0 else n.bit_length() - 1 input = sys.stdin.readline N = int(input()) strs = [input().rstrip() for _ in range(N)] M, x, d = map(int, input().split()) perm = [i for i in range(N)] perm.sort(key=lambda i: strs[i]) iperm = [0] * N for i, p in enumerate(perm): iperm[p] = i size = N - 1 lcp = [0] * size for i in range(size): s1, s2 = strs[perm[i]], strs[perm[i + 1]] lcp[i] = l = min(len(s1), len(s2)) for j in range(l): if s1[j] != s2[j]: lcp[i] = j break lgN = ilog2(size) tab = [lcp] for k in range(1, lgN + 1): s = 1 << (k - 1) prev, curr = tab[-1], [0] * (size + 1 - 2 * s) for i in range(len(curr)): curr[i] = min(prev[i], prev[i + s]) tab += [curr] ans = 0 mod = N * (N - 1) for _ in range(M): i, j = divmod(x, N - 1) j += (i <= j) i, j = iperm[i], iperm[j] if i > j: i, j = j, i l = ilog2(j - i) ans += min(tab[l][i], tab[l][j - (1 << l)]) x += d if x >= mod: x -= mod print(ans) solve()