import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); String s = sc.next(); long[] b = new long[m]; for (int i = 0; i < b.length; i++) { b[i] = sc.nextLong(); } long[] a = new long[n]; for (int i = 0; i < a.length; i++) { a[i] = sc.nextLong(); } sc.close(); long ans = 0; long suma = 0; for (int i = 0; i < a.length; i++) { suma += a[i]; } long sumb = 0; for (int i = 0; i < b.length; i++) { sumb += b[i]; } suma %= k; sumb %= k; if ("+".equals(s)) { ans = suma * m + sumb * n; } else { ans = suma * sumb; } ans %= k; System.out.println(ans); } }