#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; char op; cin >> op; ll s = 0, t = 0; for (int j = 0; j < m; j++) { int b; cin >> b; s += b; } for (int i = 0; i < n; i++) { int a; cin >> a; t += a; } s %= k; t %= k; if (op == '+') { cout << (s * n + t * m) % k << endl; } else { cout << s * t % k << endl; } return 0; }