def partition(arr, p, r)
  q = arr[r]
  i = p - 1 # ????????????
  for j in p..(r - 1) # ??????????±?
    if arr[j][1] <= q[1] then
      i = i + 1
      tmp = arr[i]
      arr[i] = arr[j]
      arr[j] = tmp
    end
  end
  z = i + 1
  tmp = arr[z]
  arr[z] = arr[r]
  arr[r] = tmp
  z
end


def quickSort(arr, p, r)
  if p < r then
    q = partition(arr, p, r)
    quickSort(arr, p, q-1)
    quickSort(arr, q+1, r)
  end
end


n = STDIN.gets.to_i

arr = []
for i in 0..(n - 1)
  c = STDIN.gets.split(' ')
  c[1] = c[1].to_i
  arr.push(c)
end

ss = arr.map { |c| c[0] }

quickSort(arr, 0, arr.size - 1)

stable = true
ss.each_with_index { |s, i|
  if s != arr[i] then
    stable = false
    break
  end
}

if stable then
  puts "Stable"
else
  puts "Not stable"
end

arr.each { |c|
  puts c.join(' ')
}