def partition(arr,p,r)
  x=arr[r][1].to_i
  i= p - 1
  #puts arr
  for j in p..r-1
    if(arr[j][1].to_i <= 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 quickSort(arr,p,r)
  if p < r
    q=partition(arr,p,r)
    quickSort(arr,p,q-1)
    quickSort(arr,q+1,r)
  end
end
def isStable(arr,arr2,n)
  0.upto(n-1) do |i|
    if(arr[i][0]!=arr2[i][0])
      return FALSE
    end
  end
  return TRUE
end
n=gets.to_i
arr=Array.new()
n.times do
  card,num=gets.split.map(&:to_s)
  arr << [card,num]
end
arr2=arr.sort()
quickSort(arr,0,n-1)
if isStable(arr,arr2,n)
  puts "Stable"
else
  puts "Not stable"
end
n.times do |i|
  puts "#{arr[i][0]} #{arr[i][1]}"
end