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 = 0L; for(int i = 0; i < m; i++) sumB = (sumB + sc.nextInt()) % k; long res = 0L; if(op == '+') { for(int i = 0; i < n; i++) res = (res + sc.nextLong() * m % k + sumB) % k; } else { for(int i = 0; i < n; i++) res = (res + sc.nextLong() * sumB % k) % k; } System.out.println(res); } }