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

typedef struct order{
  long num;
  int order;
  struct order *next;
}Order;


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);
  }
}

Order *add_order(Order *begin, long num, char mark) {
  Order *p;
  if(begin == NULL) {
    p = (Order*)malloc(sizeof(Order));
    p->num = num;
    p->order = ((int)mark-'B')%7;
    p->next = NULL;
    return p;
  }
  p = begin;
  int t;
  while(1) {
    if(p->num == num) {
      t = 1;
      while(p->order / t != 0) t *= 10;
      p->order += ((int)mark-'B')%7*t;
      break;
    }
    if(p->num > num) {
      Order *p1 = (Order*)malloc(sizeof(Order));
      p1->num = num;
      p1->order = ((int)mark-'B')%7;
      p1->next = begin;
      return p1;  
    }
    if(p->next == NULL || p->next->num > num) {
      Order *p1 = (Order*)malloc(sizeof(Order));
      p1->num = num;
      p1->order = ((int)mark-'B')%7;
      p1->next = p->next;
      p->next = p1;
      break;
    }
    p = p->next;
  }
  return begin;
}

Order *check_order(long *A, char *mark, long n) {
  long i;
  Order *begin = NULL;
  for (i = 0; i < n; i++) {
    begin = add_order(begin,A[i],mark[i]);
  }

  return begin;
}

int cmp_order(Order *a, Order *b) {
  while(a != NULL && b != NULL) {
    if(a->order != b->order) return 1;
    a = a->next;
    b = b->next;
  }
  return 0;
}

int main()
{
  long i,n,*A;
  char *mark;
  Order *order1,*order2;
  scanf("%ld ", &n);
  A = (long*)malloc(sizeof(long) * n);
  mark = (char*)malloc(sizeof(char) * n);
  for (i = 0; i < n; i++) {
    scanf("%c %ld ", mark+i, A+i);
  }
  order1 = check_order(A,mark,n);
  Quicksort(A,mark,0,n-1);
  order2 = check_order(A,mark,n);
  if(cmp_order(order1,order2) == 0) {
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

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

  return 0;
}