#include<stdio.h>
#define INF 1000000007
typedef struct{
  char moji;
  int suu;
}card;
int partition(card *,int,int);
void quickSort(card *,int,int);
void merge(card *,int,int,int);
void mergeSort(card *,int,int);
int main(){
  int n;
  card A[100001],B[100001];
  int i;
  int flag;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%c",&A[i].moji);
    scanf("%d",&A[i].suu);
    B[i] = A[i];
  }
  quickSort(A,0,n);
  mergeSort(B,0,n);
  flag = 1;
  for(i=0;i<n;i++){
    if(A[i].moji != B[i].moji){
      flag = 0;
      break;
    }
  }
  if(flag) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].moji,A[i].suu);
  }
  return 0;
}
int partition(card A[],int p,int r){
  card x = A[r-1],tmp;
  int i,j;
  j=p;
  for(i=p;i<r;i++){
    if(A[i].suu<=x.suu){
      tmp = A[i];
      A[i] = A[j];
      A[j]=tmp;
      j++;
    }
  }
  return j-1;
}
    
void quickSort(card 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 merge(card A[],int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  card L[n1],R[n2];
  int i,j,k;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1].suu = INF;
  R[n2].suu = INF;
  i = 0;
  j = 0;
  for(k=left;k<right;k++){
    if(L[i].suu<=R[j].suu) A[k] = L[i++];
    else A[k] = R[j++];
  }   
}

void mergeSort(card A[],int left,int right){
  int mid;
  if(left+1<right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

