#include #include #include #include #include #include #include #include #include #include #define int long long #define double long double #define rep(i,n) for(int i=0;i> n >> m >> k; cin >> c; rep(i, m)cin >> a[i]; rep(i, n)cin >> b[i]; if (c == '+') { int p = 0, q = 0; rep(i, m)p += a[i]; rep(i, n)q += b[i]; p %= k, q %= k; cout << (p * n + q * m) % k << endl; } else { int p = 0, q = 0; rep(i, m)p += a[i]; rep(i, n)q += b[i]; p %= k, q %= k; cout << p * q % k << endl; } }