#yuki-1359 N, K, mod = map(int, input().split()) P = sorted(map(int, input().split())) E = sorted(map(int, input().split())) A = sorted(map(int, input().split())) H = sorted(map(int, input().split())) ans = 0 for i in range(N): M = max(P[i], E[i], A[i], H[i]) m = min(P[i], E[i], A[i], H[i]) ans += pow(M-m, K, mod) ans %= mod print(ans)