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())) p.sort() e.sort() a.sort() h.sort() diff = [] for w, x, y, z in zip(p, e, a, h): diff.append(max(w, x, y, z) - min(w, x, y, z)) ans = 0 for i, d in enumerate(diff): ans += pow(d, k, m) ans %= m print(ans)