MOD = 10 ** 9 + 7 n, m, x = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def f(A): ret = 0 for a in A: ret ^= a return ret if f(A) != f(B): print(0) else: ans = pow(pow(2, x, MOD), (n - 1) * (m - 1), MOD) print(ans)