def partition(a, p, r)
	x = a[r][1]
	i = p-1
	p.upto(r-1) 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 quickSort(a, p, r)
	if p < r
		q = partition(a, p, r)
		quickSort(a, p, q-1)
		quickSort(a, q+1, r)
	end
end

INFTY = 9999999999

def merge(a, left, mid, right)
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	0.upto(n1-1) do |i|
		l[i] = a[left + i]
	end
	0.upto(n2-1) do |i|
		r[i] = a[mid + i]
	end
	l[n1] = []
	r[n2] = []
	l[n1][1] = INFTY
	r[n2][1] = INFTY
	i = 0
	j = 0
	left.upto(right-1) do |k|
		if l[i][1] <= r[j][1]
			a[k] = l[i]
			i += 1
		else
			a[k] = r[j]
			j += 1
		end
	end
end

def mergeSort(a, left, right)
	if left+1 < right
		mid = (left + right)/2
		mergeSort(a, left, mid)
		mergeSort(a, mid, right)
		merge(a, left, mid, right)
	end
end

n = gets.to_i
arr = []
n.times do
	suit, value = gets.split
	value = value.to_i
	arr.push([suit, value])
end

#quickSort
arr2 = Marshal.load(Marshal.dump(arr))
quickSort(arr2, 0, n - 1)

#mergeSort
arr3 = Marshal.load(Marshal.dump(arr))
mergeSort(arr3, 0, n)
p arr3

if arr2 == arr3
	puts "Stable"
else
	puts "Not stable"
end

puts arr2.map{|x|x[0]+" "+x[1].to_s}.join("\n")