// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <algorithm>

using namespace std;

const int INF = (1 << 30);

const int N = 100005;

struct Card

{

	char suit;

	int value;

} card[N], t[N], temp;

Card L[N / 2 + 1], R[N / 2 + 1];



void _merge(Card a[], int l, int m, int r)	//[l, r)

{

	int i, j, k;

	int n1 = m - l;

	int n2 = r - m;

	for (i = 0; i < n1; ++i)

		L[i] = a[l + i];

	for (i = 0; i < n2; ++i)

		R[i] = a[m + i];

	L[n1].value = R[n2].value = INF;

	i = j = 0;

	for (k = l; k < r; ++k)

	{

		if (L[i].value <= R[j].value)

			a[k] = L[i++];

		else

			a[k] = R[j++];

	}

}



void _merge_sort(Card arr[], int l, int r)

{

	if (l + 1 >= r)

		return;

	int m = (l + r) / 2;

	_merge_sort(arr, l, m);

	_merge_sort(arr, m, r);

	_merge(arr, l, m, r);

}



int partition(Card arr[], int p, int r)	//[p, r)????????????,????????????pivot??????

{

	int pivot = arr[r - 1].value;

	int i = p;

	for (int j = p; j < r - 1; ++j)

	{

		if (arr[j].value <= pivot)

		{

			temp = arr[i];

			arr[i++] = arr[j];

			arr[j] = temp;

		}

	}

	temp = arr[i];

	arr[i] = arr[r - 1];

	arr[r - 1] = temp;

	return i;

}



void q_sort(Card arr[], int l, int r)

{

	if (l + 1 < r)

	{

		int t = partition(arr, l, r);

		q_sort(arr, l, t);

		q_sort(arr, t, r);

	}

}



int main(void)

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i)

	{

		cin >> card[i].suit >> card[i].value;

		t[i] = card[i];

	}

	q_sort(card, 0, n);

	_merge_sort(t, 0, n);

	bool flag = true;

	for (int i = 0; i < n; ++i)

	{

		if (card[i].suit != t[i].suit)

		{

			flag = false;

			break;

		}

	}

	if (flag)

		cout << "Stable" << endl;

	else

		cout << "Not stable" << endl;



	for (int i = 0; i < n; ++i)

		cout << card[i].suit << ' ' << card[i].value << endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.199241216211338x):
#include<cstdio>

using namespace std;

#define N 100005

#define INF (1 << 30)

struct card

{

	char suit;

	int value;

};

typedef struct card card;



card L[N / 2], R[N / 2];

card a[N], b[N];

int n;



void _merge(int left, int mid, int right)

{

	int n1 = mid - left;

	int n2 = right - mid;

	for (int i = 0; i<n1; ++i)

		L[i] = a[left + i];

	for (int i = 0; i<n2; ++i)

		R[i] = a[mid + i];

	L[n1].value = R[n2].value = INF;

	int i = 0, j = 0;

	for (int k = left; k<right; k++)

	{

		if (L[i].value <= R[j].value)

			a[k] = L[i++];

		else

			a[k] = R[j++];

	}

}

void mergesort(int n, int left, int right)

{

	int mid;

	if (left + 1<right)

	{

		mid = (left + right) >> 1;

		mergesort(n, left, mid);

		mergesort(n, mid, right);

		_merge(left, mid, right);

	}

}

int _partition(int n, int p, int r)

{

	card x = b[r];

	int i = p - 1;

	for (int j = p; j<r; j++)

	{

		if (b[j].value <= x.value)

		{

			i++;

			card t = b[i];

			b[i] = b[j];

			b[j] = t;

		}

	}

	card t = b[i + 1]; b[i + 1] = b[r]; b[r] = t;

	return i + 1;

}

void quicksort(int n, int p, int r)

{

	int q;

	if (p<r)

	{

		q = _partition(n, p, r);

		quicksort(n, p, q - 1);

		quicksort(n, q + 1, r);

	}

}

int main()

{

	int stable = 1;

	scanf("%d", &n);

	for (int i = 0; i<n; ++i)

	{

		char str[3];

		int x;

		scanf("%s %d", str, &x);

		a[i].suit = b[i].suit = str[0];

		a[i].value = b[i].value = x;

	}

	mergesort(n, 0, n);

	quicksort(n, 0, n - 1);

	for (int i = 0; i<n; ++i)

	{

		if (a[i].suit != b[i].suit) stable = 0;

	}

	if (stable) printf("Stable\n");

	else printf("Not stable\n");

	for (int i = 0; i<n; ++i)

	{

		printf("%c %d\n", b[i].suit, b[i].value);

	}

	return 0;

}