#include #include using namespace std; #define int long long signed main() { int M, N, mulX, addX, mulY, addY, mod; cin >> M >> N >> mulX >> addX >> mulY >> addY >> mod; vector X(M), Y(M), A(M), B(M); for (int i = 0; i < M; ++i) cin >> X[i]; for (int i = 0; i < M; ++i) cin >> Y[i]; for (int i = 0; i < M; ++i) cin >> A[i]; for (int i = 0; i < M; ++i) cin >> B[i]; vector cnt(mod, 0); for (int i = 0; i < M; ++i) cnt[X[i]] += Y[i]; int x = X.back(), y = Y.back(); for (int i = M; i < N; ++i) { x = (1LL * x * mulX + addX) % mod; y = (1LL * y * mulY + addY) % mod; cnt[x] += y; } vector is_prime(mod, true); for (int p = 2; p < mod; ++p) { if (is_prime[p]) { for (int x = (mod - 1) / p; x > 0; --x) cnt[x] += cnt[x * p]; for (int i = 2 * p; i < mod; i += p) is_prime[i] = false; } } int ans = 0; for (int i = 0; i < M; ++i) { int a = A[i], b = B[i]; int c = 0; if (a < mod) c += cnt[a]; if (1LL * a * b < mod) c -= cnt[a * b]; cout << c << endl; ans ^= c; } int a = A.back(), b = B.back(); for (int i = M; i < N; ++i) { a = ((1LL * a * mulX + addX + mod - 1) % mod) + 1; b = ((1LL * b * mulY + addY + mod - 1) % mod) + 1; int c = 0; if (a < mod) c += cnt[a]; if (1LL * a * b < mod) c -= cnt[a * b]; ans ^= c; } cout << ans << endl; return 0; }