#include using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; ll mod; cin >> mod; char op; cin >> op; vector a(n), b(m); for(int i = 0; i < m; i++)cin >> b[i]; for(int i = 0; i < n; i++)cin >> a[i]; ll acc = 0; for(int i = 0; i < m; i++)acc += b[i], acc %= mod; ll ans = 0; for(int i = 0; i < n; i++) { if(op == '+') { ans += (a[i] * m + acc); ans %= mod; } else { ans += (acc * a[i]) % mod; ans %= mod; } } cout << ans << endl; }