MOD = 10**9+7 n, m, x = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) p = 0 for c in a: p ^= c q = 0 for d in b: q ^= d if p != q: print(0) else: print(pow(2, x * (n-1) * (m-1), MOD))