let () =
  let get_shop = function
      1 -> "A"
    | 2 -> "B"
    | 3 -> "C"
    | 4 -> "D"
    | 5 -> "E"
    | _ -> "NONE"
  in
  let rec loop max = function
      0 -> max
    | i ->
       let line = read_line ()
                  |> Str.split (Str.regexp " ")
                  |> List.map int_of_string
                  |> Array.of_list in
       let (am, pm) = (line.(0), line.(1)) in
       if am = 0 && pm = 0 then (0,0)
       else if snd max < (am+pm) then
         loop ((5-i+1),am+pm) (i-1)
       else
         loop max (i-1)
  in
  let rec read () =
    let (max_shop, ampm) = loop (0, 0) 5 in
    if max_shop = 0 then ()
    else
      begin
        Printf.printf "%s %d\n" (get_shop max_shop) ampm;
        read ()
      end
  in read ()
;;