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 p, q = 1, 1 for j in range(n): ans += p * pow(cy, n - j, MOD) * q * pow(x - cx, n - j - 1, MOD) * cx % MOD p *= y q *= x p %= MOD q %= MOD res += ans << i print(res % MOD)