# coding: utf-8 import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def IAI(LINE): return [ILI() for __ in range(LINE)] def IDI(): return {key: value for key, value in ILI()} def makeQuery(N, M, x, d): query = [] i = list(range(1, N + 1)) j = list(range(1, N + 1)) for k in range(1, M + 1): i[k] = (x // (N - 1)) + 1 j[k] = (x % (N - 1)) + 1 if i[k] > j[k]: i[k], j[k] = j[k], i[k] else: j[k] = j[k] + 1 x = (x + d) % (N * (N - 1)) for q in range(1, N): query.append((i[q], j[q])) return query def solve(N, s, M, x, d): query = makeQuery(N, M, x, d) ans = 0 for q in query: s_i = s[q[0] - 1] s_j = s[q[1] - 1] n_len = min(len(s_i), len(s_j)) l_lcp = [] n_lcp = 0 for i in range(n_len): if s_i[i] == s_j[i]: n_lcp += 1 else: l_lcp.append(n_lcp) break else: l_lcp.append(n_lcp) ans += max(l_lcp) return ans def main(): N = II() s = [input() for __ in range(N)] M, x, d = ILI() print(solve(N, s, M, x, d)) if __name__ == "__main__": main()