using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (h, w, x) = (c[0], c[1], c[2]); var a = NList; var b = NList; var ax = a.Aggregate((i, j) => i ^ j); var bx = b.Aggregate((i, j) => i ^ j); if (ax != bx) { WriteLine(0); return; } var mod = 1_000_000_007; WriteLine(Exp(Exp(2, (h - 1L) * (w - 1), mod), x, mod)); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }