let () =
  let rec get_data l = function
      0 -> l
    | i -> get_data (read_int()::l) (i-1)
  in
  let all i l = List.for_all (fun x -> x=i) l and
      ex i l = List.exists (fun x -> x=i) l
  in
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        let l = n::((get_data [] 4) |> List.rev) in
        let a = Array.of_list l in
        if (all 1 l) || (all 2 l) || (all 3 l) then
          for i = 0 to 4 do
            print_endline "3"
          done
        else if (ex 1 l) && (ex 2 l) &&  (ex 3 l) then
          for i = 0 to 4 do
            print_endline "3"
          done
        else if (ex 1 l) && (ex 2 l) then
          Array.iter (fun x -> print_endline (if x = 1 then "1" else "2")) a
        else if (ex 1 l) && (ex 3 l) then
          Array.iter (fun x -> print_endline (if x = 3 then "1" else "2")) a
        else if (ex 2 l) && (ex 3 l) then
          Array.iter (fun x -> print_endline (if x = 2 then "1" else "2")) a
        ;read ()
      end
  in read ()
;;