import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime; immutable long MOD = 10^^9 + 7; void main() { auto s = readln.split.map!(to!int); auto H = s[0]; auto W = s[1]; auto X = s[2]; auto A = readln.split.map!(to!long).array; auto B = readln.split.map!(to!long).array; long x = 0; foreach (a; A) x ^= a; foreach (b; B) x ^= b; if (x != 0) { writeln(0); return; } long ans = powmod(2, 1L*(H-1)*(W-1), MOD); ans = powmod(ans, X, MOD); ans.writeln; } long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; }