#include #include using lint = long long; void solve() { int n, m; lint k; char op; std::cin >> n >> m >> k >> op; lint xsum = 0, ysum = 0; for (int i = 0; i < m; ++i) { lint x; std::cin >> x; xsum += x; } for (int i = 0; i < n; ++i) { lint y; std::cin >> y; ysum += y; } xsum %= k, ysum %= k; std::cout << (op == '+' ? xsum * n + ysum * m : xsum * ysum) % k << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }