#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; } for (int j = 1; j < MOD; j++) { ll s = p[0]; for (int i = j; i < MOD; i += j) { s += p[i]; } p[j] = s; } 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] : p[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] : p[0]); } cout << r << endl; return 0; }