class Card

	include Comparable
	attr_accessor :suit, :number

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

	def <=>(other)
		self.number - other.number
	end

	def to_s
		"#{@suit} #{@number}"
	end

	def eql?(other)
		self.suit == other.suit && self.number == other.number
	end

end

def partition(array, from, to)
	separator = array[to]
	i = from - 1
	(from...to).each do |j|
		if array[j] <= separator
			i = i + 1
			array[i], array[j] = array[j], array[i]
		end
	end
	array[i + 1], array[to] = array[to], array[i + 1]
	i + 1
end

def quick_sort(array, from, to)
	return unless from < to
	pivot = partition(array, from, to)
	quick_sort(array, from, pivot - 1)
	quick_sort(array, pivot + 1, to)
end

def insertion_sort(array)
	start = 1
	(start...array.size).each do |i|
		current = array[i]
		j = i - 1
		while j >= 0 && array[j] > current
			array[j + 1] = array[j]
			j -= 1
		end
		array[j + 1] = current
	end
end

cards = []
array_size = STDIN.gets.to_i
array_size.times do
	suit, number = STDIN.gets.split[0..1]
	cards << Card.new(suit, number.to_i)
end

original_cards = cards.dup
quick_sort(cards, 0, array_size - 1)
insertion_sort(original_cards)
puts cards.eql?(original_cards) ? "Stable" : "Not stable"
cards.each do |c|
	puts c
end