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