#include <iostream>
#include<string>

using namespace std;
int main(void){
    int n, m, k, ans = 0;
    string ope;
    int 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;


}