while true
    n = gets.to_i
    break if n == 0
    votes = gets.chomp.split
    h = Hash.new(0)
    votes.each{|v| h[v] += 1}
    winners = h.find_all{|k, v| v == h.values.max}
    if winners.length > 1
        puts "TIE"
    else
        winner = winners[0][0]
        w, h = 0, Hash.new(0)
        h["?"] = 0
        votes.each_with_index{|v, i|
            if v == winner
                w += 1
            else
                h[v] += 1
            end
            if h.all?{|k, v| w > v + n - i - 1}
                puts "#{winner} #{i + 1}"
                break
            end
        }
    end
end

