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] } for i := 0; i < m; i++ { ans2 += side[i] } fmt.Println((ans*m + ans2*n) % k) } else { ans := 0 for i := 0; i < m; i++ { ans += side[i] } ans2 := 0 for i := 0; i < n; i++ { ans2 += ver[i] * ans } fmt.Println(ans2 % k) } }