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)
  input == out
  # n = input.length
  # for i in 0...n
  #   if input[i] != out[i]
  #     return false
  #   end
  # end
  # true
end

def bubble_sort!(arr)
  n = arr.length
  for i in 0..(n-1)
    for j in (n-1).downto(i+1)
      if arr[j].value < arr[j-1].value
        arr[j], arr[j-1] = arr[j-1], arr[j]
      end
    end
  end
  return arr
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?(bubble_sort!(cards), sorted_cards)
  puts "Stable"
else
  puts "Not stable"
end

sorted_cards.each do| card|
  puts card
end
