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