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