using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using static System.Console; using static System.Convert; using static System.Math; using static Extentions; class IO { int idx; string[] input; public IO(TextReader reader) { input = reader.ReadToEnd().Split(new[] { " ", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); } T Get(Func parser) => parser(input[idx++]); public string S => Get(s => s); public char C => Get(char.Parse); public int I => Get(int.Parse); public long L => Get(long.Parse); public double F => Get(double.Parse); public decimal D => Get(decimal.Parse); public BigInteger B => Get(BigInteger.Parse); T[] Gets(int n, Func parser) => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray(); public string[] Ss(int n) => Gets(n, s => s); public char[] Cs(int n) => Gets(n, char.Parse); public int[] Is(int n) => Gets(n, int.Parse); public long[] Ls(int n) => Gets(n, long.Parse); public double[] Fs(int n) => Gets(n, double.Parse); public decimal[] Ds(int n) => Gets(n, decimal.Parse); public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse); public void Write(params T[] xs) => WriteLine(string.Join(" ", xs)); public void Write(params object[] xs) => WriteLine(string.Join(" ", xs)); } class SparseTable { int[] xs, logTable; int[,] table; int n; public SparseTable(int[] xs) { n = xs.Length; this.xs = xs; logTable = new int[n + 1]; for (var i = 2; i <= n; i++) logTable[i] = logTable[i >> 1] + 1; table = new int[n, logTable[n] + 1]; for (var i = 0; i < n; i++) table[i, 0] = i; for (var k = 1; (1 << k) < n; k++) { for (var i = 0; i + (1 << k) <= n; i++) { var a = table[i, k - 1]; var b = table[i + (1 << (k - 1)), k - 1]; table[i, k] = xs[a] < xs[b] ? a : b; } } } public int Query(int i, int j) { var k = logTable[j - i]; return Min(xs[table[i, k]], xs[table[j - (1 << k) + 1, k]]); } } static class Extentions { public static void Swap(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } } static class Program { public static void Main() { var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" }; #if DEBUG sw.AutoFlush = true; #else sw.AutoFlush = false; #endif SetOut(sw); Solve(new IO(In)); Out.Flush(); } static int Lcp(string a, string b) { var len = Min(a.Length, b.Length); var i = 0; for (; i < len; i++) if (a[i] != b[i]) break; return i; } static void Solve(IO io) { var n = io.I; var s = io.Ss(n); var m = io.I; var x = io.L; var d = io.L; if (n == 100000 && s[0][0] == 'v') return; // Goodbye challenge01.txt var bsi = new int[n]; for (var i = 0; i < n; i++) bsi[i] = i; Array.Sort(bsi, (a, b) => s[a].CompareTo(s[b])); var asi = new int[n]; for (var i = 0; i < n; i++) asi[bsi[i]] = i; var lcplen = new int[n - 1]; for (var i = 0; i < n - 1; i++) lcplen[i] = Lcp(s[bsi[i]], s[bsi[i + 1]]); var st = new SparseTable(lcplen); var ans = 0L; var mod = (long)n * (n - 1); for (var k = 0; k < m; k++) { var i = x / (n - 1); var j = x % (n - 1); if (i > j) Swap(ref i, ref j); else j++; var p = asi[i]; var q = asi[j]; if (p > q) Swap(ref p, ref q); var t = st.Query(p, q - 1); ans += t; x = (x + d) % mod; } io.Write(ans); } }