def partition(a, m, p, r)
	x = a[r]
	i = p - 1
	for j in p..r-1
		if a[j] <= x
			i += 1
			a[j],a[i] = a[i],a[j]
			m[j],m[i] = m[i],m[j]
		end
	end
	a[r],a[i+1] = a[i+1],a[r]
	m[r],m[i+1] = m[i+1],m[r]
	return i+1
end

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

n = gets.to_i
a = Array.new
m = Array.new
num_cnt = Hash.new(Array.new)
n.times { |i|
	m[i],a[i] = gets.split(" ")
	a[i] = a[i].to_i
	j = a[i]
	num_cnt[j].push(m[i])
}

quicksort(a,m,0,n-1)

i = n - 1
f = 0
while i >= 0
	j = a[i]
	if m[i] != num_cnt[j].pop
		f = 1
		break
	end
	i -= 1
end

if f == 1
	puts "Not stable"
else
	puts "Stable"
end

i = 0
while i < n
	puts m[i] + " " + a[i].to_s
	i += 1
end