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