def partition as, p, r
  j = p - 1
  p.upto(r) do |i|
    if as[i][1].to_i <= as[r][1].to_i
      j += 1
      as[j], as[i] = as[i], as[j]
    end
  end
  return j
end

def quick_sort as, p, r
  if p < r
    q = partition as, p, r
    quick_sort as, p, q - 1
    quick_sort as, q + 1, r
  end
end

n = gets.chomp.to_i
as = []
while l = gets
  as << l.chomp.split(' ')
end
orig_orders = {}
as.each do |a|
  orig_orders[a[1].to_i] = a[0]
end
quick_sort as, 0, n - 1
new_orders = {}
as.each do |a|
  new_orders[a[1].to_i] = a[0]
end

puts orig_orders == new_orders ? 'Stable' : 'Not stable'
as.each do |a|
  puts a.join(' ')
end
