N, M, X = map(int, input().split()) P = 10 ** 9 + 7 x = 0 for a in map(int, input().split()): x ^= a for b in map(int, input().split()): x ^= b if x != 0: print(0) else: print(pow(pow(2, M * N - M - N + 1, P), X, P))