import sys def main(): MOD = 1 << 24 # Just to have it here, actual MOD is read from input input = sys.stdin.read().split() ptr = 0 M = int(input[ptr]); ptr +=1 N = int(input[ptr]); ptr +=1 mulX = int(input[ptr]); ptr +=1 addX = int(input[ptr]); ptr +=1 mulY = int(input[ptr]); ptr +=1 addY = int(input[ptr]); ptr +=1 MOD = int(input[ptr]); ptr +=1 X = list(map(int, input[ptr:ptr+M])) ptr += M Y = list(map(int, input[ptr:ptr+M])) ptr += M A = list(map(int, input[ptr:ptr+M])) ptr += M B = list(map(int, input[ptr:ptr+M])) ptr += M # Generate x, y, a, b for M+1 to N x = [0] * (N + 1) y_values = [0] * (N + 1) a = [0] * (N + 1) b = [0] * (N + 1) for i in range(1, M+1): x[i] = X[i-1] % MOD y_values[i] = Y[i-1] % MOD a[i] = A[i-1] % MOD b[i] = B[i-1] % MOD for i in range(M+1, N+1): x[i] = (x[i-1] * mulX + addX) % MOD y_values[i] = (y_values[i-1] * mulY + addY) % MOD a[i] = (a[i-1] * mulX + addX + MOD -1) % MOD +1 b[i] = (b[i-1] * mulY + addY + MOD -1) % MOD +1 # Compute z[x] z = [0] * MOD for i in range(1, N+1): xi = x[i] % MOD z[xi] += y_values[i] # Now process each query xor_total = 0 output = [] for j in range(1, M+1): aj = a[j] bj = b[j] ab = aj * bj sum_a = 0 for x in range(0, MOD, aj): sum_a += z[x] if ab <= MOD: sum_ab = 0 for x in range(0, MOD, ab): sum_ab += z[x] else: sum_ab = z[0] Sj = sum_a - sum_ab output.append(Sj) xor_total ^= Sj # Process the remaining j from M+1 to N, but in the problem statement, only the first M are output # Wait, the problem statement says that for j from M+1 to N, the answer is not output, but the XOR includes all j's. # So, for j from M+1 to N, compute Sj and XOR into xor_total. for j in range(M+1, N+1): aj = a[j] bj = b[j] ab = aj * bj sum_a = 0 for x in range(0, MOD, aj): sum_a += z[x] if ab <= MOD: sum_ab = 0 for x in range(0, MOD, ab): sum_ab += z[x] else: sum_ab = z[0] Sj = sum_a - sum_ab xor_total ^= Sj # Output the first M lines for val in output: print(val) # Output the XOR print(xor_total) if __name__ == "__main__": main()