#include <stdio.h>
#include <string.h>
#define N 100000
#define F 0
#define T 1

typedef struct {
  char c[2];
  int value;
} cards;

cards A[N], B[N], C[N];

int partition(int p, int r) {
  int i, j, x;
  cards tmp;

  x = B[r].value;
  i = p-1;
  for (j = p; j < r; j++) {
    if(B[j].value <= x) {
      i++;
      tmp = B[i];
      B[i] = B[j];
      B[j] = tmp;
    }
  }
  tmp = B[i+1];
  B[i+1] = B[r];
  B[r] = tmp;
  return i+1;
}

void quickSort(int p, int r) {
  int q;
  if (p < r) {
    q = partition(p, r);
    quickSort(p, q-1);
    quickSort(q+1, r);
  }
}

void bubbleSort(int n) {
  int i, j;
  cards tmp;

  for(i = 0; i < n; i++) {
    for(j = n-1; j > i; j--) {
      if(C[j].value < C[j-1].value) {
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
    }
  }
}

int isStable(int n) {
  int i, j, a, b, flag = 1;
  for (i = 0; i < n; i++) {
    if (i == 0) {
      a = 0;
    } else if (B[i].value != B[i - 1].value) {
      a = 0;
    } else {
      a++;
    }
    b = 0;
    for (j = 0; j < n; j++) {
      if (C[j].value == B[i].value) {
        if (a == b) {
          if (strcmp(C[j].c, B[i].c) != 0) {
            flag = 0;
          }
          break;
        }
        b++;
      }
    }
    if (flag == 0) {
      break;
    }
  }
  if (flag == 0) return F;
  else return T;
}


int main() {
  int n, i;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s%d", A[i].c, &A[i].value);
    strcpy(B[i].c, A[i].c);
    strcpy(C[i].c, A[i].c);
    B[i].value = A[i].value;
    C[i].value = A[i].value;
  }

  quickSort(0, n-1);
  bubbleSort(n);

  if(isStable(n) == F) printf("Not stable\n");
  else printf("Stable\n");
  for (i = 0; i < n; i++ ){;
    printf("%s %d\n", B[i].c, B[i].value);
  }
  return 0;

}