#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; V<> sieve(int n) { V b((n + 1) / 3, true); V<> res{2, 3}; for (int p = 5, d = 2; p * p < n; p += d, d = 6 - d) if (b[p / 3]) { for (int i = 5 * p, d = 2 * p; i < n; i += d, d = 6 * p - d) b[i / 3] = false; } for (int p = 5, d = 2; p < n; p += d, d = 6 - d) if(b[p / 3]) res.push_back(p); while (!res.empty() and res.back() >= n) res.pop_back(); return res; } template void fmult(V& a, const V<>& ps) { int n = a.size(); for (int p : ps) { for (int i = (n - 1) / p; i; --i) { a[i] += a[i * p]; } } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int m, n; cin >> m >> n; lint mulX, addX, mulY, addY, MOD; cin >> mulX >> addX >> mulY >> addY >> MOD; V<> x(n), y(n), 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]; for (int i = m; i < n; ++i) { x[i] = x[i - 1] * mulX + addX & MOD - 1; y[i] = y[i - 1] * mulY + addY & MOD - 1; } V z(MOD); for (int i = 0; i < n; ++i) { z[x[i]] += y[i]; } V<>().swap(x); V<>().swap(y); fmult(z, sieve(MOD)); lint acc = 0; for (int i = 0; i < m; ++i) { lint res = 0; if (a[i] < MOD) { res += z[a[i]]; } if ((lint)a[i] * b[i] < MOD) { res -= z[a[i] * b[i]]; } cout << res << '\n'; acc ^= res; } int na = a.back(), nb = b.back(); for (int i = m; i < n; ++i) { na = (na * mulX + addX - 1 & MOD - 1) + 1; nb = (nb * mulY + addY - 1 & MOD - 1) + 1; lint res = 0; if (na < MOD) { res += z[na]; } if ((lint)na * nb < MOD) { res -= z[na * nb]; } acc ^= res; } cout << acc << '\n'; }