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