#include typedef long long int ll; constexpr int kMod = int(1E9 + 7), kN = int(2E5 + 10); ll Pow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % kMod; a = a * a % kMod; b >>= 1; } return ans; } ll a[kN], b[kN]; int main() { ll n, m, x; scanf("%lld%lld%lld", &n, &m, &x); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= m; i++) scanf("%lld", &b[i]); for (int i = 2; i <= n; i++) b[1] ^= a[i]; for (int i = 2; i <= m; i++) a[1] ^= b[i]; if (a[1] != b[1]) printf("0\n"); else printf("%lld\n", Pow((1LL << x) % kMod, (n - 1) * (m - 1) % (kMod - 1))); }