#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int partition(int A[], int p, int r,char *p1);
void quicksort(int A[], int p, int r,char *p1);
void BubbleSort(int A[], int n, char *p);
int main() {
	int *A, *B,r, n, i;
	char m1[100000], m2[100000], *p1, *p2;
	scanf("%d", &n);
	A = (int *)malloc(sizeof(int)*n);
	B = (int *)malloc(sizeof(int)*n);
	p1 = m1; p2 = m2;
	m2[0] = '\0';
	r = n-1;
	for (i = 0; i < n; i++) { scanf("%1s %d", p1 + i, A + i); *(B + i) = *(A + i); }
	strcat(p2, p1);
	quicksort(A, 0, r,p1);
	BubbleSort(B, n, p2);
	if (strcmp(p1, p2) == 0)puts("Stable"); else puts("Not stable");
	for (i=0; i < n; i++) printf("%c %d\n", *(p1+i),*(A+i));
	free(A); free(B);
	return 0;
}

int partition(int A[], int p, int r,char *p1){
	int i,x,j,tmp;
	char cTmp[2];
	x = A[r];
	i = p-1;
	for (j = p; j <= r; j++) {
		if (A[j] <= x) {
			i++;
			tmp = A[i]; A[i] = A[j]; A[j] = tmp;
			cTmp[0] = *(p1 + i); *(p1 + i) = *(p1 + j); *(p1 + j) = cTmp[0];
		}
	}
	return i;
}

void quicksort(int A[], int p, int r,char *p1){
	int q;
	if (p < r) {
		q = partition(A, p, r,p1);
		quicksort(A, p, q - 1,p1);
		quicksort(A, q + 1, r,p1);

	}
}

void BubbleSort(int A[], int n, char *p)
{
	int i, j, tmp;
	char ctmp[2];
	for (i = 0; i < n; i++) {
		for (j = 1; j < n; j++) {
			if (*(A + j - 1) > *(A + j)) {
				tmp = *(A + j); *(A + j) = *(A + j - 1); *(A + j - 1) = tmp;
				ctmp[0] = *(p + j); *(p + j) = *(p + j - 1); *(p + j - 1) = ctmp[0];
			}
		}
	}
}