#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; char op; cin >> op; vector a(n), b(m); for (int i = 0; i < m; ++i) { cin >> b[i]; } for (int i = 0; i < n; ++i) { cin >> a[i]; } long long sum_b = accumulate(b.begin(), b.end(), 0LL); sum_b %= k; long long sum_a = accumulate(a.begin(), a.end(), 0LL); sum_a %= k; if (op == '+') cout << (sum_a * m + sum_b * n) % k << '\n'; else cout << (sum_a * sum_b) % k << '\n'; return 0; }