#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; vector b(m),a(n); rep(i,m)cin>>b[i]; rep(i,n)cin>>a[i]; ll ans=0; if(op=='+'){ rep(i,n)ans+=(a[i]*n)%k; rep(i,m)ans+=(b[i]*m)%k; }else{ ll hoge=0,shake=0; rep(i,n)hoge+=a[i]; rep(i,m)shake+=b[i]; ans=(hoge*shake)%k; } cout<