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