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(); boolean isPlus = (sc.next().charAt(0) == '+'); long colums = 0; for (int i = 0; i < m; i++) { colums += sc.nextInt(); colums %= k; } long rows = 0; for (int i = 0; i < n; i++) { rows += sc.nextInt(); rows %= k; } if (isPlus) { System.out.println((colums * n + rows * m) % k); } else { System.out.println(colums * rows % k); } } }