N, K, M = map(int, input().split()) P = list(map(int, input().split())) E = list(map(int, input().split())) A = list(map(int, input().split())) H = list(map(int, input().split())) res = 0 for t in zip(sorted(P), sorted(E), sorted(A), sorted(H)): res += pow(max(t) - min(t), K, M) res %= M print(res)