import numpy as np import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) mod = 10 ** 9 + 7 N, M, X = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) for _ in range(X): A, ma = np.divmod(A, 2) B, mb = np.divmod(B, 2) if (ma.sum() + mb.sum()) % 2 == 1: print(0) exit() cnt = pow(2, N - 1, mod) ans = pow(cnt, X * (M - 1), mod) print(ans)