N,X,Y = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) P = 998244353 ans = 0 for i in range(18): a = 0 b = 0 mask = 1 << i for j in A: if mask & j:a += 1 for j in B: if mask & j:b += 1 tmp = 0 for j in range(1,N + 1): t = pow(X,j - 1,P) * a * pow(X - a,N - j,P) % P * pow(Y,j - 1,P) * pow(b,N - j + 1,P) % P tmp += t tmp %= P ans += tmp * mask % P print(ans % P)