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 x = 1 y = 1 if b == 0:continue if a == X: tmp = pow(X,N - 1,P) * a * pow(Y,N - 1,P) * b % P ans += tmp continue u = a * pow(X - a,N - 1,P) * pow(b,N,P) % P r = X * Y * pow(b * (X - a),P - 2,P) % P if r == 1: v = N else: v = (1 - pow(r,N,P)) * pow(1 - r,P - 2,P) % P ans += u * v % P * mask % P print(ans % P)