#include using namespace std; int main() { int N, M, K; char op; cin >> N >> M >> K >> op; vector A(N), B(M); for (auto &b : B) cin >> b; for (auto &a : A) cin >> a; long ans = 0; if (op == '+') { for (int i = 0; i < N; i++) (ans += A.at(i) * M) %= K; for (int i = 0; i < M; i++) (ans += B.at(i) * N) %= K; } else { long a = accumulate(A.begin(), A.end(), 0L) % K; long b = accumulate(B.begin(), B.end(), 0L) % K; ans = a * b % K; } cout << ans << "\n"; }