import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N, M, X = getlist() A = getlist() B = getlist() ans = pow(2, (M - 1) * (N - 1) * X, con) jud = 0 for _ in range(X): cnt = 0 for i in range(N): if A[i] % 2 == 1: cnt += 1 A[i] >>= 1 for i in range(M): if B[i] % 2 == 1: cnt += 1 B[i] >>= 1 if cnt % 2 == 1: jud = 1 break if jud == 1: print(0) else: print(ans) if __name__ == '__main__': main()