while true
    arr = [0, 0, 0, 0]
    hands = []
    hands << gets.to_i
    break if hands.last == 0
    arr[hands.last] += 1
    4.times{
        hands << gets.to_i
        arr[hands.last] += 1
    }

    arr.shift
    if arr.count(0) == 0 || arr.count(0) == 2
        5.times{puts 3}
    else
        case arr.index(0)
        when 0
            hands.map!{|h| h - 1}
        when 1
            hands.map!{|h| h == 1 ? 2 : 1}
        end
        puts hands
    end
end

