#include<stdio.h>
#include<stdlib.h>
#define MAX 500000
#define INF 2000000000
typedef struct Cards{
  int number;
  char mark;
}card;
void quickSort(card [], int, int);
int partition(card [], int, int);
void swapCard(card *, card *);
void merge(card [], int, int, int, int);
void mergeSort(card [], int, int, int);
int isStable(card [], card[], int);
card L[MAX/2+2], R[MAX/2+2];
int main(){
  int n, i, num;
  char c;
  card *Q, *M;

  scanf("%d",&n);
  Q = malloc(sizeof(card) * n);
  M = malloc(sizeof(card) * n);
  for (i = 0; i < n; i++) {
    scanf(" %c %d", &c, &num);
    M[i].number = num;
    M[i].mark = c;
    Q[i].number = num;
    Q[i].mark = c;
  }
  quickSort(Q,0,n-1);
  mergeSort(M, n, 0, n-1);
  if ( isStable(Q, M, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }
  for (i = 0; i < n; i++) {
    printf("%c %d\n", Q[i].mark, Q[i].number);
  }
  return 0;
}
void quickSort(card Q[], int p, int r){
  int q;
  if ( p < r ) {
    q = partition(Q, p, r);
    quickSort(Q, p, q-1);
    quickSort(Q, q+1, r);
  }
  return ;
}
int partition(card Q[], int p, int r){
  int i, j, key;
  key = Q[r].number;
  j = p-1;
  for (i = p; i < r; i++) {
    if ( Q[i].number <= key ) {
      j++;
      swapCard(&Q[i], &Q[j]);
    }
  }
  swapCard(&Q[j+1], &Q[r]);
  return j+1;
}
void mergeSort(card M[], int n, int left, int right){
  int mid;
  if( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(M, n, left, mid);
    mergeSort(M, n, mid+1, right);
    merge(M, n, left, mid, right);
  }
  return;
}
void merge(card M[], int n, int left, int mid, int right){
  int i, j, k, n1, n2;
  n1 = mid - left;
  n2 = right - mid;
  for (i = 0; i < n1; i++) {
    L[i] = M[left + i];
  }
  for (i = 0; i < n2; i++) {
    R[i] = M[mid + 1];
  }
  L[n1].number = INF;
  R[n2].number = INF;
  i = 0;
  j = 0;
  for(k = left; k < right; k++) {
    if ( L[i].number <= R[j].number ) {
      M[k] = L[i];
      i++;
    } else {
      M[k] = R[j];
      j++;
    }
  }
}
void swapCard(card *Q1, card *Q2){
  card tmp;
  tmp = *Q1;
  *Q1 = *Q2;
  *Q2 = tmp;
  return ;
}
int isStable(card Q[], card M[], int n){
  int i, j;
  for (i = 0;i < n; i++) {
    if ( Q[i].mark != M[i].mark) {
      return 0;
    }
  }
  return 1;
}