#include using namespace std; typedef long long ll; int main() { int N, M; ll K; cin >> N >> M >> K; ll A[N], B[M]; string op; cin >> op; for (int i = 0; i < M; i++) { cin >> B[i]; } ll v = 0; for (int i = 0; i < N; i++) { cin >> A[i]; v += A[i]; v %= K; } if (op == "+") { ll sum = 0; for (int i = 0; i < N; i++) { sum += A[i] * M; sum %= K; } for (int i = 0; i < M; i++) { sum += B[i] * N; sum %= K; } cout << sum << "\n"; } else { ll sum = 0; for (int i = 0; i < M; i++) { sum += v * B[i]; sum %= K; } cout << sum << "\n"; } return 0; }