def partition(a, p ,r)
  x = a[r][1]
  i = p-1
  (p...r).each do |j|
    if a[j][1] <= x
      i += 1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[r] = a[r], a[i+1]
  return i+1
end

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

n = gets.to_i

a = Array.new(n){ Array.new(2) }

n.times do |i|
  a[i] = gets.split
  a[i][1] = a[i][1].to_i
end
arr = a.clone

quick_sort(a, 0, n-1)
i = 0
arr.sort_by! do |item|
  i += 1
  [item[1], i]
end
bool = true
(0...n).each do |i|
  if a[i][0] != arr[i][0] || a[i][1] != arr[i][1]
    bool = false
    break
  end 
end
puts "Stable" if bool
puts "Not stable" unless bool
a.each do |ele|
  puts ele.join(" ")
end