const MOD: usize = 998244353; fn main() { let mut nxy = String::new(); std::io::stdin().read_line(&mut nxy).ok(); let nxy: Vec = nxy.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nxy[0]; let x = nxy[1]; let y = nxy[2]; let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let BITS = 18; let mut dp = vec![vec![0usize; BITS]; 2*n+1]; let mut patterns = 1usize; for times in 0..n { for &v in a.iter() { for i in 0..BITS { dp[2*times+1][i] += dp[2*times][i] + ((v >> i) & 1) * (MOD + patterns - dp[2*times][i]); dp[2*times+1][i] %= MOD; } } patterns *= x; patterns %= MOD; for &v in b.iter() { for i in 0..BITS { if ((v >> i) & 1) == 1 { dp[2*times+2][i] += dp[2*times+1][i]; dp[2*times+2][i] %= MOD; } } } patterns *= y; patterns %= MOD; } println!("{}", (0..BITS).map(|i| dp[2*n][i] * (1usize << i) % MOD).sum::() % MOD) }