import Control.Monad
import Control.Applicative

isDraw :: [Int] -> Bool
isDraw xs =
    let allRock = all (1 ==) xs
        allScissors = all (2 ==) xs
        allPaper = all (3 ==) xs
        allHands = elem 1 xs && elem 2 xs && elem 3 xs
    in allRock || allScissors || allPaper || allHands

solve :: [Int] -> [Int]
solve xs
    | isDraw xs = replicate (length xs) 3
    | otherwise =
        let rockWin = elem 1 xs && elem 2 xs
            scissorsWin = elem 2 xs && elem 3 xs
        in if rockWin then map (\x -> if x == 1 then 1 else 2) xs
           else if scissorsWin then map (\x -> if x == 2 then 1 else 2) xs
           else map (\x -> if x == 3 then 1 else 2) xs

main :: IO ()
main = do
    h1 <- read <$> getLine
    if h1 == 0 then return ()
    else do
        h2 <- read <$> getLine
        h3 <- read <$> getLine
        h4 <- read <$> getLine
        h5 <- read <$> getLine
        mapM_ print $ solve [h1, h2, h3, h4, h5]
        main

