#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvvl vector #define vvl vector> #define VV(a, b, c, d) vector>(a, vector(b, c)) #define VVV(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c> n >> m >> k; char c;std::cin >> c; vll a(n), b(m); get(b); get(a); if(c=='+'){ ll ans = 0; re(i, m) ans = (ans + b[i]*n)%k; re(i, n) ans = (ans + a[i]*m)%k; std::cout << ans << '\n'; }else{ ll A = 0, B = 0; re(i, n) A = (A + a[i])%k; re(i, m) B = (B + b[i])%k; std::cout << (A*B)%k << '\n'; } return 0; }