MOD = 10 ** 9 + 7 N,M,X = map(int,input().split()) A= list(map(int,input().split())) B = list(map(int,input().split())) 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)