#include #define rep(i,n) for(int i = 0; i < int(n); i++) #define rrep(i,n) for(int i = int(n)-1; i >= 0; i--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back using namespace std; using ll = long long; using P = pair; int dx[] = {1, 0,-1, 0, 1, 1,-1,-1}; int dy[] = {0, 1, 0,-1, 1,-1, 1,-1}; int mod = 998244353; int MOD = 1000000007; int inf = 1001001001; ll INF = 1001001001001001001; ll mod_pow(ll x,ll y,ll m) { ll res = 1; while(y > 0) { if(y%2) { res = res*x%m; } x = x*x%m; y /= 2; } return res; } int main() { int N; cin >> N; ll K,M; cin >> K >> M; vectorP(N),E(N),A(N),H(N); rep(i,N) { cin >> P[i]; } sort(all(P)); rep(i,N) { cin >> E[i]; } sort(all(E)); rep(i,N) { cin >> A[i]; } sort(all(A)); rep(i,N) { cin >> H[i]; } sort(all(H)); int ans = 0; rep(i,N) { ans += mod_pow(max({P[i],E[i],A[i],H[i]})-min({P[i],E[i],A[i],H[i]}),K,M); ans %= M; } cout << ans << endl; }