import java.math.BigInteger import java.util.Scanner import scala.math.BigInt.javaBigInteger2bigInt object Main extends App { val sc = new Scanner(System.in) val n = sc.nextInt val m = sc.nextInt val k = sc.nextInt val op = sc.next val arr = Array.fill(m)(sc.nextBigInteger) val brr = Array.fill(n)(sc.nextBigInteger) val opf = op match { case "+" => (x:BigInteger, y:BigInteger) => (x + y) case "*" => (x:BigInteger, y:BigInteger) => (x * y) } println(brr.map(b => arr.map(a => opf(a, b)).sum % k).sum % k) }