#include <stdio.h>
#define exchange(a,b) {typeof(a) __tmp=a;a=b;b=__tmp;}


char A[100001];
int B[100001];


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

void Quicksort(int 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);
  }
}

void Bubblesort(int A[], int n) {
  int i,j;
  for(i = n; i >= 2; --i) {
    for(j = 2; j <= i; ++j) {
      if(B[A[j-1]] > B[A[j]])
	exchange(A[j-1], A[j]);
    }
  }
}

int main() {
  int i;
  int n;
  int C1[100001],C2[100001];
  int isStable;
  scanf("%d", &n);
  for(i = 1; i <= n; ++i) {
    scanf(" %c %d", A+i,B+i);
    C1[i] = C2[i] = i;
  }
  Quicksort(C1,1,n);
  Bubblesort(C2,n);
  isStable = 1;
  for(i = 1; i <= n; ++i) {
    if(A[C1[i]] != A[C2[i]]) {
      isStable = 0;
      break;
    }
  }
  if(isStable) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 1; i <= n; ++i) {
    printf("%c %d\n", A[C1[i]], B[C1[i]]);
  }
  return 0;
}