import Control.Monad

main :: IO ()
main = do
  n1 <- readLn
  if n1 == 0
    then return ()
    else do
      ns <- replicateM 4 readLn
      let ns' = n1:ns
          ans = solve ns'
      mapM_ print ans
      main

solve :: [Int] -> [Int]
solve ns
  | allEq ns = [3,3,3,3,3]
  | allDif ns = [3,3,3,3,3]
  | not (elem 1 ns) = fix 1 ns
  | not (elem 2 ns) = fix 2 ns
  | not (elem 3 ns) = fix 3 ns
  where
    allEq :: [Int] -> Bool
    allEq ns = all ((==) (head ns)) ns

    allDif :: [Int] -> Bool
    allDif ns = (elem 1 ns) && (elem 2 ns) && (elem 3 ns)

    fix :: Int -> [Int] -> [Int]
    fix _ [] = []
    fix 1 (x:xs)
      | x == 2 = 1:(fix 1 xs)
      | otherwise = 2:(fix 1 xs)
    fix 2 (x:xs)
      | x == 1 = 2:(fix 2 xs)
      | otherwise = 1:(fix 2 xs)
    fix 3 (x:xs)
      | x == 1 = 1:(fix 3 xs)
      | otherwise = 2:(fix 3 xs)