# 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)) query.append((i[k] - 1, j[k] - 1)) return query def makeLcp(N, s): lcp = [[0] * N for __ in range(N)] for i in range(N - 1): for j in range(i, N): s_i = s[i] s_j = s[j] n_len = min(len(s_i), len(s_j)) n_lcp = 0 for k in range(n_len): if s_i[k] == s_j[k]: n_lcp += 1 else: break lcp[i][j] = n_lcp lcp[j][i] = n_lcp return lcp def solve(N, s, M, x, d): query = makeQuery(N, M, x, d) lcp = makeLcp(N, s) ans = 0 for i, j in query: ans += lcp[i][j] 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()