import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int k = Integer.parseInt(sa[1]); int m = Integer.parseInt(sa[2]); int[] p = na(br); int[] e = na(br); int[] a = na(br); int[] h = na(br); br.close(); long ans = 0; for (int i = 0; i < n; i++) { int min = Math.min(p[i], e[i]); min = Math.min(min, a[i]); min = Math.min(min, h[i]); int max = Math.max(p[i], e[i]); max = Math.max(max, a[i]); max = Math.max(max, h[i]); int d = max - min; ans += powMod(d, k, m); } System.out.println(ans % m); } static int[] na(BufferedReader br) throws Exception { String[] sa = br.readLine().split(" "); int[] a = new int[sa.length]; for (int i = 0; i < sa.length; i++) { a[i] = Integer.parseInt(sa[i]); } Arrays.sort(a); return a; } static long powMod(long x, long n, int m) { assert 0 <= n : "n=" + n; assert 1 <= m : "m=" + m; if (m == 1) { return 0; } long r = 1; long y = x % m; if (y < 0) { y += m; } while (n > 0) { if ((n & 1) == 1) { r = r * y % m; } y = y * y % m; n >>= 1; } return r; } }