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

int Partition(int *A, char *C, int f, int l){
  int i, j, x;
  char c;
  i = f-1;
  for(j = f; j < l; j++){
    if(A[j] <= A[l]){
      i = i+1;
      x = A[j];
      A[j] = A[i];
      A[i] = x;

      c = C[j];
      C[j] = C[i];
      C[i] = c;
    }
  }
    x = A[i+1];
    A[i+1] = A[l];
    A[l] = x;

    c = C[i+1];
    C[i+1] = C[l];
    C[l] = c;

  return i+1;
}

void Quicksort(int *A, char *C, int f, int l){
  int q;
  if(f < l){
    q = Partition(A,C,f,l);
    Quicksort(A,C,f,q-1);
    Quicksort(A,C,q+1,l);
  }
}

void Bubblesort(int *A, char *C, int n){
  int i, j, x;
  char c;
  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(A[j] < A[j-1]){
	x = A[j];
	A[j] = A[j-1];
	A[j-1] = x;
	c = C[j];
	C[j] = C[j-1];
	C[j-1] = c;
      }
    }
  }
}
int main(){
  int i, n, m, *A;
  char *B, *C;
  scanf("%d",&n);
  A = malloc(sizeof(int)*n);
  B = malloc(sizeof(char)*n);
  C = malloc(sizeof(char)*n);
  for(i = 0; i < n; i++){
    scanf(" %c%d",&C[i], &A[i]);
  }
  strcpy(B,C);
  Bubblesort(A,B,n);
  Quicksort(A,C,0,n-1);
  if(strcmp(B,C) == 0) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n",C[i],A[i]);
  }
  return 0;
}