#include <stdio.h>
#include <string.h>
#define MAX_N 100000

struct card_t {
	char s;
	int n;
};
typedef struct card_t Card;

int patition(Card a[MAX_N], int p, int r) {
	int x, i, j, t;
	char c;

	x = a[r].n;
	i = p - 1;
	for (j = p; j < r; j++) {
		if (a[j].n <= x) {
			i += 1;
			c = a[i].s;
			t = a[i].n;
			a[i].s = a[j].s;
			a[i].n = a[j].n;
			a[j].s = c;
			a[j].n = t;
		}
	}
	c = a[i+1].s;
	t = a[i+1].n;
	a[i+1].s = a[r].s;
	a[i+1].n = a[r].n;
	a[r].s = c;
	a[r].n = t;
	return i + 1;
}

void quick_sort(Card a[MAX_N], int p, int r) {
	int q;

	if (p < r) {
		q = patition(a, p, r);
		quick_sort(a, p, q-1);
		quick_sort(a, q+1, r);
	}
}

int main(void) {
	Card in[MAX_N], out[MAX_N];
	int n, i, flag[MAX_N] = {0}, j, aa, bb;
	char a[5], b[5];
	const char *stable;

	scanf("%d ", &n);
	for (i = 0; i < n; i++) {
		scanf("%c %d ", &in[i].s, &in[i].n);
		out[i].s = in[i].s;
		out[i].n = in[i].n;

		for (j = 0; j < n; j++) {
			if (flag[j] == in[i].n || !flag[j]) {
				flag[j] = in[i].n;
				break;
			}
		}
	}
	quick_sort(in, 0, n-1);

	stable = "Stable";
	for (j = 0; flag[j] != 0; j++) {
		aa = bb = 0;
		a[3] = '\0';
		for (i = 0; i < n; i++) {
			if (in[i].n == flag[j]) {
				a[aa++] = in[i].s;
			}
			if (a[3] != '\0')
				break;
		}
		a[aa] = '\0';
		b[3] = '\0';
		for (i = 0; i < n; i++) {
			if (out[i].n == flag[j]) {
				b[bb++] = out[i].s;
			}
			if (b[3] != '\0')
				break;
		}
		b[bb] = '\0';
		if (strcmp(a, b) != 0) {
			stable = "Not stable";
			break;
		}
	}
	puts(stable);

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

	return 0;
}