from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M,X = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) mod = 10**9 + 7 ta = 0 tb = 0 for a in A: ta ^= a for b in B: tb ^= b if ta!=tb: print(0) exit() if min(N,M)==1: print(1) exit() S = pow(2,X,mod) ans = pow(S,(N-1)*(M-1),mod) print(ans)