use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let h: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let k: u64 = it.next().unwrap().parse().unwrap();
    let op = it.next().unwrap().chars().next().unwrap();
    let b: Vec<u64> = (0..w).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let a: Vec<u64> = (0..h).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let sum_a = a.into_iter().fold(0, |a, s| a + s) % k;
    let sum_b = b.into_iter().fold(0, |a, s| a + s) % k;
    let ans = if op == '+' {
        sum_a * w as u64 + sum_b * h as u64
    } else {
        sum_a * sum_b
    } % k;
    println!("{}", ans);
}

fn main() {
    run();
}