import java.io.*; import java.util.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int[] countsX = new int[19]; for (int i = 0; i < x; i++) { int v = sc.nextInt(); for (int j = 0; j <= 18 && v > 0; j++) { countsX[j] += v % 2; v >>= 1; } } int[] countsY = new int[19]; for (int i = 0; i < y; i++) { int v = sc.nextInt(); for (int j = 0; j <= 18 && v > 0; j++) { countsY[j] += v % 2; v >>= 1; } } long ans = 0; for (int i = 0; i <= 18; i++) { long[][][] matrix = new long[19][2][2]; matrix[0][0][0] = (x * y - countsX[i] * countsY[i]) % MOD; matrix[0][0][1] = x * (y - countsY[i]) % MOD; matrix[0][1][0] = countsX[i] * countsY[i] % MOD; matrix[0][1][1] = x * countsY[i] % MOD; for (int j = 1; j <= 18; j++) { for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { for (int c = 0; c < 2; c++) { matrix[j][a][c] += matrix[j - 1][a][b] * matrix[j - 1][b][c]; matrix[j][a][c] %= MOD; } } } } long[] current = new long[2]; current[0] = (1 << i); int z = n; for (int j = 18; j >= 0; j--) { if (z >= (1 << j)) { z -= (1 << j); long[] next = new long[2]; for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { next[a] += matrix[j][a][b] * current[b] % MOD; next[a] %= MOD; } } current = next; } } ans += current[1]; ans %= MOD; } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }