import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const M = readInt(); const N = readInt(); const MULX = readLong(); const ADDX = readLong(); const MULY = readLong(); const ADDY = readLong(); const MOD = readLong(); auto X = new long[M]; auto Y = new long[M]; auto A = new long[M]; auto B = new long[M]; foreach (i; 0 .. M) X[i] = readLong(); foreach (i; 0 .. M) Y[i] = readLong(); foreach (i; 0 .. M) A[i] = readLong(); foreach (i; 0 .. M) B[i] = readLong(); const len = cast(int)(MOD + 1); auto f = new long[len]; long x, y; foreach (i; 0 .. N) { if (i < M) { x = X[i]; y = Y[i]; } else { // x[i] = (x[i-1] * mulX + addX) % MOD // y[i] = (y[i-1] * mulY + addY) % MOD x = (x * MULX + ADDX) & (MOD - 1); y = (y * MULY + ADDY) & (MOD - 1); } debug { writefln("x = %s, y = %s", x, y); } f[cast(size_t)(x)] += y; } debug { writeln("f = ", f); } auto isnp = new bool[len]; foreach (p; 2 .. len) { if (!isnp[p]) { for (int m = (len - 1) / p, n = m * p; m > 0; --m, n -= p) { isnp[n] = true; f[m] += f[n]; } } } debug { writeln("f = ", f); } long ansSum; long a, b; foreach (i; 0 .. N) { if (i < M) { a = A[i]; b = B[i]; } else { // a[i] = (a[i-1] * mulX + addX + MOD - 1) % MOD + 1 // b[i] = (b[i-1] * mulY + addY + MOD - 1) % MOD + 1 a = ((a * MULX + ADDX + MOD - 1) & (MOD - 1)) + 1; b = ((b * MULY + ADDY + MOD - 1) & (MOD - 1)) + 1; } long ans = f[cast(size_t)(a)]; if (a * b < len) { ans -= f[cast(size_t)(a * b)]; } debug { writeln(a, " ", b, ": ", ans); } if (i < M) { writeln(ans); } ansSum ^= ans; } writeln(ansSum); } } catch (EOFException e) { } }