#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int lint; typedef pair IP; typedef pair LLP; typedef pairCP; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define sort(v) sort((v).begin(), (v).end()) #define reverse(v) reverse((v).begin(), (v).end()) #define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge) #define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge) #define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge) #define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge) const lint MOD = pow(10, 9) + 7; int main() { lint N, M, K; cin >> N >> M >> K; char op; cin >> op; vectorB(M); rep(i, M) { cin >> B[i]; } vectorA(N); rep(i, N) { cin >> A[i]; } if (op == '+') { lint suma = 0; lint sumb = 0; rep(i, N) { suma += A[i]; suma %= K; } rep(i, M) { sumb += B[i]; sumb %= K; } cout << (suma%K* M%K + sumb%K * N%K) % K << endl; } else { lint suma = 0; lint sumb = 0; rep(i, N) { suma += A[i]; suma %= K; } rep(i, M) { sumb += B[i]; sumb %= K; } cout << suma % K* sumb% K << endl; } }