import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int mod; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); mod = sc.nextInt(); int[][] values = new int[4][n]; for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { values[i][j] = sc.nextInt(); } Arrays.sort(values[i]); } long ans = 0; for (int i = 0; i < n; i++) { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int j = 0; j < 4; j++) { min = Math.min(min, values[j][i]); max = Math.max(max, values[j][i]); } ans += pow(max - min, k); ans %= mod; } System.out.println(ans); } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % mod, p / 2); } else { return pow(x, p - 1) * x % mod; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }