using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k, m) = (c[0], c[1], c[2]); var p = NList; var e = NList; var a = NList; var h = NList; Array.Sort(p); Array.Sort(e); Array.Sort(a); Array.Sort(h); var ans = 0L; for (var i = 0; i < n; ++i) { var max = Math.Max(Math.Max(p[i], e[i]), Math.Max(a[i], h[i])); var min = Math.Min(Math.Min(p[i], e[i]), Math.Min(a[i], h[i])); ans = (ans + Exp(max - min, k, m)) % m; } WriteLine(ans); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }