#include #define int long long using namespace std; signed main() { int N, M, K; cin >> N >> M >> K; char op; cin >> op; vector B(M); for( int i = 0; i < M; i++ ) cin >> B.at(i); vector A(N); for( int i = 0; i < N; i++ ) cin >> A.at(i); if( op == '+' ){ int ans = 0; for( int i = 0; i < M; i++ ) ans = (ans+B.at(i)*N)%K; for( int i = 0; i < N; i++ ) ans = (ans+A.at(i)*M)%K; cout << ans%K << endl; }else{ int tate = 0; int yoko = 0; for( int i = 0; i < M; i++ ) yoko = (yoko+B.at(i))%K; for( int i = 0; i < N; i++ ) tate = (tate+A.at(i))%K; cout << tate*yoko%K << endl; } }