#include using namespace std; using ll=long long; #define rep2(i, a, n) for(int i = (a); i < (n); i++) #define rep(i, n) rep2(i,0,n) int main(){ cin.tie(nullptr);ios_base::sync_with_stdio(false); int n,m,k; cin>>n>>m>>k; char op; cin>>op; int a[m],b[n]; rep(i,m)cin>>a[i]; rep(i,n)cin>>b[i]; int p=0,q=0; rep(i,m)p+=a[i]; rep(i,n)q+=b[i]; p%=k,q%=k; if (op=='+'){ cout<<(p*n+q*m)%k<