class Card
  attr_reader :suit, :value
  def initialize(card_str)
    @suit = card_str[0]
    @value = card_str[1..-1].to_i
  end

  def to_s
    @suit + ' ' + @value.to_s
  end

  def ==(other)
    if other.is_a?(Card)
      suit == other.suit && value == other.value
    else
      false
    end
  end
end

def is_stable?(input, out)
  n = input.length
  for i in 0...n
    for j in (i+1)...n
      for a in 0...n
        for b in (a+1)...n
          if input[i].value == input[j].value && input[i] == out[b] && input[j] == out[a]
            return false
          end
        end
      end
    end
  end
  true
end

def partition(arr, p, r)
  x = arr[r].value
  i = p - 1
  for j in p...r
    if arr[j].value <= x
      i += 1
      arr[i], arr[j] = arr[j], arr[i]
    end
  end
  arr[i + 1], arr[r] = arr[r], arr[i + 1]
  return i + 1
end

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

n = gets.to_i
cards = []
n.times do
  cards << Card.new(gets)
end

sorted_cards = cards.dup
quick_sort(sorted_cards, 0, n-1)
if is_stable?(cards, sorted_cards)
  puts "Stable"
else
  puts "Not stable"
end

sorted_cards.each do| card|
  puts card
end
