n, m, k = gets.split.map(&:to_i) op, *b = gets.chomp.split b.map!(&:to_i) a = [] n.times{ a << gets.to_i } sum = 0 n.times do |i| m.times do |j| sum += [a[i], b[j]].inject(:"#{op}") sum %= k end end puts sum