def main(): import sys 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 # Initialize z array z = [0] * MOD # Process eels for i=1 to M for i in range(M): x_i = X[i] y_i = Y[i] z[x_i] += y_i # Generate eels for i=M+1 to N if M < N: x_prev = X[-1] y_prev = Y[-1] for i in range(M, N): x_i = (x_prev * mulX + addX) % MOD y_i = (y_prev * mulY + addY) % MOD z[x_i] += y_i x_prev, y_prev = x_i, y_i # Precompute sum_d sum_d = [0] * MOD for d in range(1, MOD): sum_d[d] = sum(z[k] for k in range(0, MOD, d)) # Process rabbits xor_all = 0 output_M = [] # Process first M rabbits for j in range(M): a_j = A[j] b_j = B[j] m_j = a_j * b_j if m_j >= MOD: ans_j = sum_d[a_j] else: if m_j < MOD: ans_j = sum_d[a_j] - sum_d[m_j] else: ans_j = sum_d[a_j] output_M.append(ans_j) xor_all ^= ans_j # Generate rabbits for j=M+1 to N if M < N: a_prev = A[-1] b_prev = B[-1] for j in range(M, N): a_j = (a_prev * mulX + addX + MOD - 1) % MOD + 1 b_j = (b_prev * mulY + addY + MOD - 1) % MOD + 1 m_j = a_j * b_j if m_j >= MOD: ans_j = sum_d[a_j] else: if m_j < MOD: ans_j = sum_d[a_j] - sum_d[m_j] else: ans_j = sum_d[a_j] xor_all ^= ans_j a_prev, b_prev = a_j, b_j # Output for ans in output_M: print(ans) print(xor_all) if __name__ == "__main__": main()