function swap(A, i, j) {
	var tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
}

function partition(A, p, r) {
	var x = A[r].num;
	var i = p - 1;
	for (var j = p; j < r; j++) {
		if (A[j].num <= x) {
			i++;
			swap(A, i, j);
		}
	}
	swap(A, i + 1, r);

	return i + 1;
}

function sort(A, p, r) {
	if (p < r) {
		var q = partition(A, p, r);
		sort(A, p, q - 1);
		sort(A, q + 1, r);
	}
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

var n = +lines.shift();

var line;
var A = [];
var C = {};
while (line = lines.shift()) {
	var arr = line.split(' ');
	A.push({suit: arr[0], num: +arr[1]});

	var str = C[arr[1]] || '';
	C[arr[1]] = str + arr[0];
}

sort(A, 0, n - 1);

var isStable = true;
for (var i = 0; i < n; i++) {
	var e = A[i];
	var str = C[e.num + ''];
	if (str.substr(0, 1) != e.suit) {
		isStable = false;
		break;
	}
	C[e.num + ''] = str.substr(1);
}
console.log(isStable ? 'Stable' : 'Not stable');

A.forEach(function(e) {
	console.log(e.suit + ' ' + e.num);
});