#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; char op; cin >> op; long long A=0, B=0; REP (i, m) { int tmp; cin >> tmp; B += tmp; } REP (i, n) { int tmp; cin >> tmp; A += tmp; } long long ret = 0; A %= k, B %= k; if (op == '+') ret = (m * A % k + n * B % k) % k; else ret = A * B % k; cout << ret << endl; return 0; }