loop do
    a = []
    a << gets.to_i
    break if a[0] == 0
    4.times { a << gets.to_i }
    case a.uniq.map{|i| 1 << i-1}.inject(:|)
    when 1, 2, 4, 7
        puts [3] * 5
    when 3
        puts a
    when 6
        puts a.map {|x| x - 1}
    when 5
        puts a.join.tr("31", "12").split("")
    end
end