//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

A = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline);
A.shift();
A = A.map(function (line) {
  var ary = line.split(' ');
  return {'suit': ary[0], 'number': parseInt(ary[1], 10)};
});

B = [].concat(A);
sort(B, 0, B.length);
console.log(is_stable(A, B) ? 'Stable' : 'Not stable');
for (i in B) console.log('%s %d', B[i].suit, B[i].number);

function sort(A, p, r) {
  if (r - p >= 2) {
    q = partition(A, p, r);
    sort(A, p, q);
    sort(A, q+1, r);
  }
}

function partition(A, p, r) {
  var x, i, j, tmp;
  x = A[r - 1].number;
  i = p;
  for (j = p; j < r - 1; j++) {
    if (A[j].number <= x) {
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
      i++;
    }
  }
  tmp = A[i];
  A[i] = A[r - 1];
  A[r - 1] = tmp;
  return i;
}

function get_doubled_numbers(ary) {
  var numbers, res, i, cur, cnt;
  numbers = ary.map(function (x) { return x.number; });
  numbers.sort(function (a, b) { return a - b; });
  res = [];
  cur = 0;
  cnt = 0;
  for (i in numbers) {
    if (numbers[i] !== cur) {
      if (cnt >= 2) res.push(cur);
      cur = numbers[i];
      cnt = 1;
    } else {
      cnt++;
    }
  }
  if (cnt >= 2) res.push(cur);
  return res;
}

function is_this_number(card) {
  return card.number === this.number;
}

function equal(cards1, cards2) {
  for (var i in cards1)
    if (cards1[i].suit !== cards2[i].suit) return false;
  return true;
}

function is_stable(A, B) {
  var doubled, i, filter_object, a, b;
  doubled = get_doubled_numbers(A);
  for (i in doubled) {
    filter_object = {'number': doubled[i]};
    a = A.filter(is_this_number, filter_object);
    b = B.filter(is_this_number, filter_object);
    if (!equal(a, b)) return false;
  }
  return true;
}