#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll M, N, mulX, addX, mulY, addY, MOD; cin >> M >> N >> mulX >> addX >> mulY >> addY >> MOD; vector X(M), Y(M); vector A(M), B(M); rep(i, M) cin >> X[i]; rep(i, M) cin >> Y[i]; rep(i, M) cin >> A[i]; rep(i, M) cin >> B[i]; vector cnt((1 << 24) + 1); rep(i, M) { cnt[X[i]] += Y[i]; } int x = X[M - 1]; int y = Y[M - 1]; for (int i = M; i < N; i++) { x = (x * mulX + addX) % MOD; y = (y * mulY + addY) % MOD; cnt[x] += y; } vector table(cnt.size(), true); table[0] = false; table[1] = false; for (int i = 2; i < cnt.size(); i++) { if (table[i]) { for (int j = i * 2; j < cnt.size(); j += i) { table[j] = false; } for (int j = (cnt.size() - 1) / i * i; j >= i; j -= i) { cnt[j / i] += cnt[j]; } } } ll ans = 0; rep(i, M) { ll s = cnt[A[i]] - cnt[min(1 << 24, (ll)A[i] * B[i])]; ans ^= s; cout << s << endl; } int a = A[M - 1]; int b = B[M - 1]; for (int i = M; i < N; i++) { a = (a * mulX + addX + MOD - 1) % MOD + 1; b = (b * mulY + addY + MOD - 1) % MOD + 1; ll s = cnt[a] - cnt[min(1 << 24, (ll)a * b)]; ans ^= s; } cout << ans << endl; }