// yuki 988 N×Mマス計算(総和) // 2020.2.15 bal4u #include typedef long long ll; #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void out(int n) { // 非負整数の表示(出力) int i; char b[30]; if (!n) pc('0'); else { i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } pc('\n'); } int main() { int i, j, N, M, K, op, A; ll B, ans; N = in(), M = in(), K = in(); op = (gc() == '+'), gc(); B = 0; for (i = 0; i < M; ++i) B += in(); B %= K; ans = 0; for (j = 0; j < N; ++j) { A = in(); if (op) ans += (B+A*M) % K; else ans += A*B % K; } out((int)(ans % K)); return 0; }