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

def quick_sort(array, from, to)
  if from < to then
    q = partition(array, from, to)
    quick_sort(array, from, q-1)
    quick_sort(array, q+1, to)
  end
end

def merge(array, from, mid, to)
  array1 = array[from..mid]
  array2 = array[mid+1..to]
  array1 << ["", (10**9 + 1)]
  array2 << ["", (10**9 + 1)]
  i1 = 0
  i2 = 0
  new_array = []

  (to-from+1).times do
    if (array1[i1][1] <= array2[i2][1]) then
      new_array << array1[i1]
      i1 += 1
    else
      new_array << array2[i2]
      i2 += 1
    end
  end

  array[from, (to-from+1)] = new_array
end

def merge_sort(array, from, to)
  mid = (from + to) / 2
  if (to - from) > 1 then
    merge_sort(array, from, mid)
    merge_sort(array, mid+1, to)
  end
  merge(array, from, mid, to)
end

n = gets.chomp.to_i
array_orig = []
(n).times do 
  input = (gets.chomp.split)
  input[1] = input[1].to_i
  array_orig << input
end

array_quick = array_orig.dup
quick_sort(array_quick, 0, array_quick.size-1)
# p array_quick

array_merge = array_orig.dup
merge_sort(array_merge, 0, array_merge.size-1)
# p array_merge

is_stable = true
(0).upto(array_orig.size-1) do |index|
  if (array_quick[index] != array_merge[index]) then
    is_stable = false
  end
end
puts (is_stable ? "Stable" : "Not stable")

array_quick.each do |item|
  puts item.join(' ')
end