#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M; ll K; cin >> N >> M >> K; char op; cin >> op; vector<ll> A(N),B(M); for (int i=0;i<M;++i) cin >> B[i]; for (int i=0;i<N;++i) cin >> A[i]; ll ans=0; if (op=='+'){ for (int i=0;i<N;++i) (ans+=A[i]*M%K)%=K; for (int i=0;i<M;++i) (ans+=B[i]*N%K)%=K; } else { ll sum=0; for (int i=0;i<M;++i) (sum+=B[i]%K)%=K; for (int i=0;i<N;++i) (ans+=A[i]*sum%K)%=K; } cout << ans << '\n'; }