package main import ( "bufio" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) func Scanner() string { sc.Scan() return sc.Text() } func main() { buf := make([]byte, 0) sc.Buffer(buf, 100000007) sc.Split(bufio.ScanWords) n, _ := strconv.Atoi(Scanner()) m, _ := strconv.Atoi(Scanner()) k, _ := strconv.Atoi(Scanner()) mark := Scanner() ver := make([]int, n) side := make([]int, m) for i := 0; i < m; i++ { side[i], _ = strconv.Atoi(Scanner()) } for i := 0; i < n; i++ { ver[i], _ = strconv.Atoi(Scanner()) } if mark == "+" { ans := 0 ans2 := 0 for i := 0; i < n; i++ { ans += ver[i] % k ans %= k } for i := 0; i < m; i++ { ans2 += side[i] % k ans2 %= k } fmt.Println((ans*m%k + ans2*n%k) % k) } else { ans := 0 for i := 0; i < m; i++ { ans += side[i] % k ans %= k } ans2 := 0 for i := 0; i < n; i++ { ans2 += ver[i] * ans % k ans2 %= k } fmt.Println(ans2) } }