#include <stdio.h>
#include <stdlib.h>

#define MIN_N 1
#define MAX_N 100000
#define MIN_NUM 1
#define MAX_NUM 1000000000

#define SWAP(x, y) {Card z = x; x = y; y = z;}

typedef struct {
	char color;
	int num;
} Card;

Card cards[MAX_N];
int is_stable = 1;

void quick_sort(int left, int right)
{
	int pivot_i = left;
	int pivot = cards[pivot_i].num;
	int i = left, j = right;

	if(i + 1 > j)
		return;

	while(i < j) {
		if(cards[i].num < pivot) {
			i++;
			continue;
		}
		if(cards[j].num > pivot) {
			j--;
			continue;
		}
		if(cards[i].num == cards[j].num)
			is_stable = 0;

		SWAP(cards[i], cards[j]);
		i++;
		j--;
	}
	SWAP(cards[j], cards[pivot_i]);
	quick_sort(left, j);
	quick_sort(j + 1, right);
}

int main(void)
{
	int i, n;

	scanf("%d\n", &n);

	for(i = 0; i < n; i++) {
		char color;
		int num;

		scanf("%c %d\n", &color, &num);
		cards[i].color = color;
		cards[i].num = num;
	}
	quick_sort(0, n - 1);

	if(is_stable)
		puts("Stable");
	else
		puts("Not stable");

	for(i = 0; i < n; i++) {
		printf("%c %d\n", cards[i].color, cards[i].num);
	}

	return 0;
}