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