#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair P; int main() { long N, M,K; char op; cin >> N >> M >>K >> op; vector A(N), B(M); ll num=0; rep(i, M) cin >> B.at(i); rep(i, N) cin >> A.at(i); rep(i,N){ rep(j,M){ ll a = op == '+' ? B.at(j) + A.at(i) : B.at(j) * A.at(i); num = (num + a) % K; } } cout << num << endl; }