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 = new long[m]; for (int i = 0; i < m; i++) { colums[i] = sc.nextInt(); } int[] rows = new int[n]; for (int i = 0; i < n; i++) { rows[i] = sc.nextInt(); } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { long value; if (isPlus) { value = colums[j] + rows[i]; } else { value = colums[j] * rows[i]; } ans += (int)(value % k); ans %= k; } } System.out.println(ans); } }