#pragma GCC optimize("Ofast") #include using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define all(x) x.begin(),x.end() #define ln '\n' const long double PI = acos(-1.0L); const long long MOD = 1000000007LL; // const long long MOD = 998244353LL; typedef long long ll; typedef pair pii; typedef pair pll; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; } ////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N,M,K; cin >> N >> M >> K; char c; cin >> c; vector B(M),A(N); rep(i,M) cin >> B[i]; rep(i,N) cin >> A[i]; if (c == '+') { ll ans = 0; rep(i,N) { ans += M*A[i]; ans %= K; } rep(i,M) { ans += N*B[i]; ans %= K; } cout << ans << ln; } else { ll val = accumulate(all(A),0LL)%K; ll ans = 0; rep(i,M) { ans += B[i]*val; ans %= K; } cout << ans << ln; } }