#include <stdio.h>

typedef struct _card {
	int number;
	char suit;
} CARD;

CARD A[100000], I[100000];

void exchange(CARD *a, CARD *b);
int Partition(CARD A[], int p, int r);
void Quicksort(CARD A[], int p, int r);

int main(void) {
	int n;
	char str[20];
	int stable = 1;
	int i, j, c, d;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; ++i) {
		scanf("%s", str);
		A[i].suit = str[0];
		scanf("%d", &A[i].number);
		I[i] = A[i];
	}
	
	Quicksort(A, 0, n - 1);
	
	for (i = 0; i < n; ++i) {
		if (i == 0) {
			c = 0;
		} else if (A[i].number != A[i - 1].number) {
			c = 0;
		} else {
			++c;
		}
		d = 0;
		for (j = 0; j < n; ++j) {
			if (I[j].number == A[i].number) {
				if (c == d) {
					if (I[j].suit != A[i].suit) {
						stable = 0;
					}
					break;
				}
				++d;
			}
		}
		if (stable == 0) {
			break;
		}
	}
	
	if (stable == 1) {
		puts("Stable");
	} else {
		puts("Not stable");
	}
	
	for (i = 0; i < n; ++i) {
		printf("%c %d\n", A[i].suit, A[i].number);
	}
	
	return 0;
}

void exchange(CARD *a, CARD *b) {
	CARD t = *a;
	*a = *b;
	*b = t;
}

int Partition(CARD A[], int p, int r) {
	CARD x = A[r];
	int i = p - 1;
	int j;
	for (j = p; j < r; ++j) {
		if (A[j].number < x.number) {
			++i;
			exchange(&A[i], &A[j]);
		}
	}
	exchange(&A[i + 1], &A[r]);
	return i + 1;
}

void Quicksort(CARD A[], int p, int r) {
	int q;
	if (p < r) {
		q = Partition(A, p, r);
		Quicksort(A, p, q - 1);
		Quicksort(A, q + 1, r);
	}
}