n = gets.to_i
until n == 0
    ohaziki = 32
    arry = gets.split(" ").map{|k| k.to_i }
    i = 1
    bro = 0
    until ohaziki == 0
        if i % 2 == 1
            if ohaziki <= 5
                ohaziki = 1
                puts ohaziki
            else
                ohaziki -= (ohaziki - 1) % 5
                puts ohaziki
            end
        elsif i % 2 == 0
            if arry[bro] >= ohaziki
               ohaziki = 0
               puts ohaziki
            else
               ohaziki -= arry[bro]
               puts ohaziki
               if bro == n-1
                   bro = 0
               else
                   bro += 1
               end
            end
        end
        i += 1
    end
    n = gets.to_i
end
