class QuickSort

  class Card
    attr_accessor :mark, :number

    def initialize(mark, number)
      @mark = mark
      @number = number
    end

  end

  # Example:
  # a ::= [ "D 3", "H 2", "D 1" ]
  def initialize(a)
    @cards = []
    @stable = true
    a.each do |pair|
      mark, number = pair.split
      @cards << Card.new(mark, number.to_i)
    end
  end

  def solve(p, r)
    if p < r
      q = partition(p, r)
      solve(p, q-1)
      solve(q+1, r)
    end
  end

  def dump
    puts @stable ? "Stable" : "Not stable"
    @cards.each do |card|
      puts "#{card.mark} #{card.number}"
    end
  end

  private

    def partition(p, r)
      x = @cards[r].number
      i = p - 1
      (p..r-1).each do |j|
        if @cards[j].number <= x
          i += 1
          @stable = stable_swap?(i, j) if @stable
          @cards[i], @cards[j] = @cards[j], @cards[i]
        end
      end
      @stable = stable_swap?(i+1, r) if @stable
      @cards[i+1], @cards[r] = @cards[r], @cards[i+1]
      return i+1
    end

    def stable_swap?(i, j)
      if i < j
         @cards[i+1..j].each do |card|
           if card.mark != @cards[i].mark &&
              card.number == @cards[i].number
             return false
           end
         end
         @cards[i..j-1].each do |card|
           if card.mark != @cards[j].mark &&
              card.number == @cards[j].number
             return false
           end
         end
      end
      return true
    end

end

n = gets.to_i
cards = (1..n).collect {|i| gets }

qs = QuickSort.new cards
qs.solve(0, n-1)
qs.dump