import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); char op = sc.next().charAt(0); long sumB = 0; for (int i = 0; i < m; i++) { sumB += sc.nextInt(); } sumB %= k; long sumA = 0; for (int i = 0; i < n; i++) { sumA += sc.nextInt(); } sumA %= k; if (op == '+') { System.out.println((sumA * m + sumB * n) % k); } else { System.out.println(sumA * sumB % k); } } }