MOD = 10 ** 9 + 7 N,M,X = map(int,input().split()) A= list(map(int,input().split())) B = list(map(int,input().split())) if M == 1: N,M = M,N A,B = B,A if N == 1: a = A[0] for b in B: a ^= b if a == 0: print(1) else: print(0) exit() t1 = 0 for a in (A+B): t1 ^= a if t1 == 0: ans = pow(pow(pow(2,N-1,MOD),M-1,MOD),X,MOD) print(ans) else: print(0)