#include using namespace std; using ll = long long; using PII = std::pair; using PLL = std::pair; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) const int mod = 1e9 + 7; ll cal(ll r, ll c, char op) { if (op == '*') return r * c; if (op == '+') return r + c; return 0; } int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif ll h, w, k, r, c, x; ll d; char op; cin >> h >> w >> k >> op; r = c = 0; rep(i, w) cin >> x, c += x; rep(i, h) cin >> x, r += x; if (op == '*') cout << (r * c) % k << endl; else cout << ((r * w) + (c * h)) % k << endl; return 0; }