let get_wday m d =
  let days_of_month = [|31;29;31;30;31;30;31;31;30;31;30;31|] in
  let days_of_month_total =
    if m = 0 then 0
    else Array.fold_left (+) 0 (Array.sub days_of_month 0 m) in
  let days_of_year = days_of_month_total + d in
  (days_of_year+3) mod 7;;

let () =
  let print_wday w =
    let wday =
      match w with
        0 -> "Sunday"
      | 1 -> "Monday"
      | 2 -> "Tuesday"
      | 3 -> "Wednesday"
      | 4 -> "Thursday"
      | 5 -> "Friday"
      | 6 -> "Saturday"
      | w -> print_int w;"Whatever"
    in print_endline wday
  in
  let rec read () =
    let a = read_line () |> Str.split (Str.regexp " ")
            |> List.map int_of_string |> Array.of_list
    in if a.(0) = 0 && a.(1) =0 then ()
       else
         print_wday (get_wday (a.(0)-1) a.(1))
  in read ()
;;