MOD = 998244353 n, x, y = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) res = 0 for i in range(18): ans = 0 cx = 0 for j in range(x): if (a[j] >> i) & 1: cx += 1 cy = 0 for j in range(y): if (b[j] >> i) & 1: cy += 1 d = [1] * n p, q = 1, cy for j in range(n): d[j] *= p * cx d[n - j - 1] *= q p *= y * x q *= cy * (x - cx) p %= MOD q %= MOD res += sum(d) << i print(res % MOD)