// #include using namespace std; #define fi first #define se second #define all(x) x.begin(), x.end() #define lch (o << 1) #define rch (o << 1 | 1) typedef double db; typedef long long ll; typedef unsigned int ui; typedef pair pint; typedef tuple tint; const int N = 2e5 + 5; const int INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; int MOD; ll qpow(ll bas, int t) { ll ret = 1; while (t) { if (t & 1) ret = ret * bas % MOD; bas = bas * bas % MOD; t >>= 1; } return ret; } int a[4][N]; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m >> MOD; for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) cin >> a[i][j]; sort(a[i], a[i] + n); } ll ans = 0; for (int i = 0; i < n; i++) { vector tmp; for (int j = 0; j < 4; j++) tmp.push_back(a[j][i]); sort(all(tmp)); ll det = (tmp.back() - tmp.front()) % MOD; ans += qpow(det, m); } ans = (ans % MOD + MOD) % MOD; cout << ans << endl; return 0; }