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