#include #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair; //N×Mマス計算 int main() { ll n,m,k; cin >> n >> m >> k; char op; cin >> op; ll b; ll b_sum=0; rep(i,m)cin >> b,b_sum+=b; ll a; ll a_sum = 0; rep(i,n)cin >> a,a_sum+=a; if(op == '+'){ cout << (n*b_sum+m*a_sum)%k; }else{ cout << (a_sum*b_sum)%k; } return 0; } /* やっほい!        やほほい!     +    *     ∧∧  . ∧∞∧ * * ヽ(=´ω`)人(´ω`*)ノ  .~( O x.) (   O)~ + 。*   ∪    ∪ */