#include using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint n, m, k; cin >> n >> m >> k; string op; cin >> op; vector b(m); for (int i = 0; i < m; ++i) { cin >> b[i]; } vector a(n); lint atot = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; atot += a[i]; atot %= k; } lint ret = 0; for (int i = 0; i < m; ++i) { if (op == "+") { ret += n * b[i] + atot; } else { ret += b[i] * atot; } ret %= k; } cout << ret << "\n"; return 0; }