#define _USE_MATH_DEFINES #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() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; int main() { int m, n, mulX, addX, mulY, addY, mod; cin >> m >> n >> mulX >> addX >> mulY >> addY >> mod; int mod_1 = mod - 1; vector mp(mod, 0LL); vector X(m); REP(i, m) cin >> X[i]; ll x, y; REP(i, m) { x = X[i]; cin >> y; mp[x] += y; } FOR(i, m, n) { x = (x * mulX + addX) & mod_1; y = (y * mulY + addY) & mod_1; mp[x] += y; } ll ans = 0; int cri = sqrt(mod); vector memo(cri, -1LL); REP(i, m) cin >> X[i]; REP(i, m) { x = X[i]; cin >> y; if (x == 0 || y == 0) { cout << 0 << '\n'; continue; } ll cnt = 0; if (x >= cri) { for (int i = x; i < mod; i += x) cnt += mp[i]; } else { if (memo[x] == -1) { memo[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[mul] == -1) { memo[mul] = 0; for (int i = mul; i < mod; i += mul) memo[mul] += mp[i]; } cnt -= memo[mul]; } } cout << cnt << '\n'; ans ^= cnt; } FOR(i, m, n) { x = ((x * mulX + addX + mod_1) & mod_1) + 1; y = ((y * mulY + addY + mod_1) & mod_1) + 1; if (x == 0 || y == 0) continue; ll cnt = 0; if (x >= cri) { for (int i = x; i < mod; i += x) cnt += mp[i]; } else { if (memo[x] == -1) { memo[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[mul] == -1) { memo[mul] = 0; for (int i = mul; i < mod; i += mul) memo[mul] += mp[i]; } cnt -= memo[mul]; } } ans ^= cnt; } cout << ans << '\n'; return 0; }