import sys from operator import itemgetter read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) S = read().split() M, X, D = map(int, S[-3:]) inds, words = zip(*sorted(enumerate(S[:-3], 1), key=itemgetter(1))) re_index = [0] * (N+1) for i,x in enumerate(inds): re_index[x] = i def LCP_naive(S, T): n = 0 for s,t in zip(S,T): if s != t: break n += 1 return n A = [LCP_naive(S, T) for S, T in zip(words, words[1:])] N = len(A) sp = [0] * (20 * N) for n in range(N): sp[n] = A[n] for i in range(1, 20): dx = 1 << i if N < dx: break for n in range(i*N, i*N+N + 1- dx): sp[n] = min(sp[n-N], sp[n-N+dx//2]) def lcp(i,j): i = re_index[i] j = re_index[j] items = j - i if items == 1: return A[i] k = (items - 1).bit_length() - 1 dx = 1 << k return min(sp[k*N+i], sp[k*N+j-dx]) answer = 0 MOD = N * (N+1) for _ in range(M): i = X // N + 1 j = X % N + 1 if i > j: i,j = j,i else: j += 1 answer += lcp(i,j) X = (X + D) % MOD print(answer)