import numpy as np

N, M, X = map(int, input().split())
A = np.fromstring(input(), dtype=np.int64, sep=' ')
B = np.fromstring(input(), dtype=np.int64, sep=' ')
MOD = 10 ** 9 + 7
if np.bitwise_xor.reduce(A) == np.bitwise_xor.reduce(B):
    print(pow(pow(2, (N - 1) * (M - 1), MOD), X, MOD))
else:
    print(0)