#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; using i32 = int32_t; int main() { i64 n, m, k; char op; cin >> n >> m >> k >> 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]; i64 ans = 0; if (op == '+') { for (int i = 0; i < n; ++i) ans += m * a[i]; for (int i = 0; i < m; ++i) ans += n * b[i]; } else { i64 x = 0, y = 0; for (int i = 0; i < n; ++i) x += a[i]; for (int i = 0; i < m; ++i) y += b[i]; ans = (x % k) * (y % k); } cout << ans % k << endl; return 0; }