N, K, M = map(int, input().split()) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) D = sorted(map(int, input().split())) F = 0 for abcd in zip(A, B, C, D): x = max(abcd) y = min(abcd) F += pow(x - y, K, M) F %= M print(F)