import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); //n行 int m = stdIn.nextInt(); //m列 int k = stdIn.nextInt(); //割る値 String op = stdIn.next(); int[] b = new int[m]; for (int i = 0; i < m; i++) { b[i] = stdIn.nextInt(); } int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = stdIn.nextInt(); } long sum = 0; if(op.equals("+")) { for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { sum += (long)a[i]+b[j]; } } sum%=k; }else { for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { sum += ((long)a[i] * b[j]) % k; } } sum %= k; } System.out.println(sum); } }