import java.util.Scanner; import java.util.Arrays; public class No1359 { private static long modpow(long x, long n, long m) { long ret = 1; while (n > 0) { if ((n & 1) != 0) { ret = ret * x % m; } x = x * x % m; n >>= 1; } return ret; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int K = scan.nextInt(); int M = scan.nextInt(); int[] P = new int[N]; for (int i=0; i < N; i++) { P[i] = scan.nextInt(); } Arrays.sort(P); int[] E = new int[N]; for (int i=0; i < N; i++) { E[i] = scan.nextInt(); } Arrays.sort(E); int[] A = new int[N]; for (int i=0; i < N; i++) { A[i] = scan.nextInt(); } Arrays.sort(A); int[] H = new int[N]; for (int i=0; i < N; i++) { H[i] = scan.nextInt(); } Arrays.sort(H); scan.close(); long D = 0; long min = 0, max = 1; for (int i=0; i < N; i++) { int p = P[i]; int e = E[i]; min = Math.min(p, e); max = Math.max(p, e); int a = A[i]; int h = H[i]; min = Math.min(min, Math.min(a, h)); max = Math.max(max, Math.max(a, h)); D = (D + modpow(max - min, (long)K, (long)M)) % M; } System.out.println(D); } }