#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int m, n, mulX, addX, mulY, addY, mod; cin >> m >> n >> mulX >> addX >> mulY >> addY >> mod; vector mp(mod, 0); vector X(m); REP(i, m) cin >> X[i]; long long x, y; REP(i, n) { if (i < m) { x = X[i]; cin >> y; } else { x = (x * mulX + addX) & (mod - 1); y = (y * mulY + addY) & (mod - 1); } mp[x] += y; } long long ans = 0; int cri = sqrt(mod); unordered_map memo; REP(i, m) cin >> X[i]; REP(i, n) { if (i < m) { x = X[i]; cin >> y; } else { x = ((x * mulX + addX + mod - 1) & (mod - 1)) + 1; y = ((y * mulY + addY + mod - 1) & (mod - 1)) + 1; } if (x == 0 || y == 0) { if (i < m) cout << 0 << '\n'; continue; } long long cnt = 0; if (x >= cri) { for (int i = x; i < mod; i += x) cnt += mp[i]; } else { if (memo.count(x) == 0) { for (int i = x; i < mod; i += x) memo[x] += mp[i]; } cnt += memo[x]; } if (x * y < mod) { int mul = x * y; if (mul >= cri) { for (int i = mul; i < mod; i += mul) cnt -= mp[i]; } else { if (memo.count(mul) == 0) { for (int i = mul; i < mod; i += mul) memo[mul] += mp[i]; } cnt -= memo[mul]; } } if (i < m) cout << cnt << '\n'; ans ^= cnt; } cout << ans << '\n'; return 0; }