#include <stdio.h>
#include <stdlib.h>

void swap(long *A, long i, long j) {
  long temp;
  temp = A[i];
  A[i] = A[j];
  A[j] = temp;
}

void swap_mark(char *A, long i, long j) {
  char temp;
  temp = A[i];
  A[i] = A[j];
  A[j] = temp;
}

long Partition(long *A,char *mark, long p, long r) {
  long i,j,x;
  x = A[r];
  i = p-1;
  for(j = p; j < r; j++) {
    if(A[j] <= x) {
      i++;
      swap(A,i,j);
      swap_mark(mark,i,j);
    }
  }
  swap(A,i+1,r);
  swap_mark(mark,i+1,r);
  return i+1;
}

void Quicksort(long *A, char *mark, long p, long r) {
  if (p < r) {
    long q = Partition(A,mark,p,r);
    Quicksort(A,mark,p,q-1);
    Quicksort(A,mark,q+1,r);
  }
}

int *check_stable(long *A, char *mark, long n, long max) {
  long i;
  int t;
  int *check = (int*)calloc(max+1,sizeof(int));
  for (i = 0; i < n; i++) {
    t = 1;
    while(check[A[i]] / t != 0) t *= 10;
    check[A[i]]+=((int)mark[i]-'B')%7*t;
  }

  return check;
}

int main()
{
  long i,n,*A,max;
  char *mark;
  int *check1,*check2;
  scanf("%ld ", &n);
  A = (long*)malloc(sizeof(long) * n);
  mark = (char*)malloc(sizeof(char) * n);
  max = 0;
  for (i = 0; i < n; i++) {
    scanf("%c %ld ", mark+i, A+i);
    if(max < A[i]) max = A[i];
  }
  check1 = check_stable(A,mark,n,max);
  Quicksort(A,mark,0,n-1);
  check2 = check_stable(A,mark,n,max);
  for (i = 0; i <= max; i++) {
    if(check1[i] != check2[i]) {
      printf("Not stable\n");
      break;
    }
    if(i == max) printf("Stable\n");
  }

  for (i = 0; i < n; i++) {
    printf("%c %ld\n",mark[i],A[i]);
  }

  return 0;
}