#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; ll N, M, K; ll A[101010], B[101010], col, row; char op; int main() { cin >> N >> M >> K; cin >> op; for (int i = 1; i <= M; i++) cin >> B[i]; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) row += A[i]; for (int i = 1; i <= M; i++) col += B[i]; if (op == '+') { cout << (M * row % K + N * col % K) % K << endl; } else { cout << (row * col) % K << endl; } return 0; }