import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;

  auto ai = new card[](n);
  foreach (i; n.iota) {
    auto rd = readln.chomp.splitter(' ');
    auto suite = rd.front; rd.popFront;
    auto value = rd.front.to!int;
    ai[i] = card(suite, value);
  }

  auto stable = true;
  quicksort(ai, 0, n - 1, stable);

  foreach (a; ai)
    writefln("%s %d", a.suite, a.value);
  writeln(stable ? "Stable" : "Not stable");
}

size_t partition(ref card[] ai, size_t p, size_t r, ref bool stable)
{
  auto x = ai[r];
  auto i = p - 1;

  foreach (j; p..r) {
    if (ai[j].value <= x.value) {
      ++i;
      swap(ai[i], ai[j]);
      if (ai[i].value == ai[j].value) stable = false;
    }
  }
  swap(ai[i + 1], ai[r]);
  if (ai[i + 1].value == ai[r].value) stable = false;

  return i + 1;
}

void quicksort(ref card[] ai, size_t p, size_t r, ref bool stable)
{
  if (p < r) {
    auto q = partition(ai, p, r, stable);
    quicksort(ai, p, q - 1, stable);
    quicksort(ai, q + 1, r, stable);
  }
}

alias Tuple!(string, "suite", int, "value") card;