let split str =
  let rec split_inner ct b=
    if String.length str = ct then [int_of_string b]
    else
      match str.[ct] with
        ' ' -> (int_of_string b)::split_inner (ct+1) ""
      | c -> split_inner (ct+1) (b^(Char.escaped c))
  in split_inner 0 "";;

let () =
  let f x y =
    let matrix_multi m2 m1 =
      List.fold_left (fun p q -> (List.fold_left2 (fun a b1 c1 -> a + b1 * c1) 0 q m2)::p) [] m1
      |> List.rev and
        read_list u = read_line u |> split in
    let rec read fin i =
      let line = fin () in
      if i <= 0 then [line] else line::read fin (i-1)in
    let result = matrix_multi (read read_int (y-1)) (read read_list (x-1))
    in List.iter (fun e-> string_of_int e |> print_endline) result
  in match read_line () |> split with
       [a;b] ->f a b
     | _ -> ();;