#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll mod = 1000000007; const ll INF = (1e+18) + 7; #define rep(i,n) for(int i=0;i=0;i--) #define all(x) (x).begin(),(x).end() #define stop char nyaa;cin>>nyaa; using P = pair; using LP = pair; void solve() { int h, w; cin >> h >> w; ll m; cin >> m; char c; cin >> c; vector a(h), b(w); rep(j, w)cin >> b[j]; rep(i, h)cin >> a[i]; if (c == '+') { ll ans = 0; rep(i, h) { ans += a[i] * w; ans %= m; } rep(j, w) { ans += b[j] * h; ans %= m; } cout << ans << endl; } else { ll sa = 0, sb = 0; rep(i, h)sa += a[i]; rep(j, w)sb += b[j]; sa %= m; sb %= m; cout << sa * sb%m << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); //int t; cin >> t;rep(i,t) solve(); solve(); stop return 0; }