#include #include #include #include #include #include #include using namespace std; using ll = long long; ll p[1 << 24]; int main() { ios::sync_with_stdio(false); cin.tie(0); int m, n; cin >> m >> n; int m0, m1, m2, m3; cin >> m0 >> m1 >> m2 >> m3; int MOD; cin >> MOD; ll mask = MOD - 1; vector x0(m); for (int i = 0; i < m; i++) { cin >> x0[i]; } ll x = x0.back(), y; for (int i = 0; i < m; i++) { cin >> y; p[x0[i]] += y; } for (int i = m; i < n; i++) { x = (x * m0 + m1) & mask; y = (y * m2 + m3) & mask; p[x] += y; } vector q(MOD); for (int i = 2; i * i < MOD; i++) { if (q[i]) continue; for (int j = i * i; j < MOD; j += i) { q[j] = true; } } for (int i = 2; i < MOD; i++) { if (q[i]) continue; for (int j = (MOD - 1) / i; j > 0; j--) { p[j] += p[j * i]; } } vector a0(m); for (int i = 0; i < m; i++) { cin >> a0[i]; } ll r = 0; ll a, b; for (int i = 0; i < m; i++) { a = a0[i]; cin >> b; ll c = a * b; ll t = p[a] - (c < MOD ? p[a * b] : 0); cout << t << '\n'; r ^= t; } for (int i = m; i < n; i++) { a = (a * m0 + m1) & mask; b = (b * m2 + m3) & mask; ll c = a * b; r ^= p[a] - (c < MOD ? p[a * b] : 0); } cout << r << endl; return 0; }