MOD=10**9+7 N,M,X=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) ans=1 for x in range(X): a=[(v>>x)%2 for v in A] b=[(v>>x)%2 for v in B] if sum(a)%2!=sum(b)%2: exit(print(0)) ans=ans*pow(2,(N-1)*(M-1),MOD)%MOD print(ans)