import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int m = sc.nextInt(); int[][] rates = new int[4][n]; for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { rates[i][j] = sc.nextInt(); } Arrays.sort(rates[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, rates[j][i]); max = Math.max(max, rates[j][i]); } ans += powmod(max - min, k, m); ans %= m; } System.out.println(ans); } static long powmod(long x, long p, int mod) { if (p == 0) { return 1; } else if (p % 2 == 0) { return powmod(x * x % mod, p / 2, mod); } else { return powmod(x, p - 1, mod) * x % mod; } } }