#include #include using namespace std; using ll = long long int; int main(void){ ll n, m, k, ans = 0; string ope; ll b = 0, a = 0, btmp; cin >> n >> m >> k >> ope; for(int i = 0; i < m; i++){ cin >> btmp; b += btmp; b %= k; } if (ope == "*"){ for(int i = 0; i < n; i++){ cin >> a; ans += a * b; ans %= k; } } else{ int atmp; for(int i = 0; i < n; i++){ cin >> atmp; a += atmp; a %= k; } ans = a * m + b * n; ans %= k; } cout << ans << endl; return 0; }