import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
struct Card
{
    char suit;
    int value;
    mixin Proxy!value;
}
size_t partition(T)(T A)
{
    auto x = A[A.length - 1];
    auto i = -1;
    for (auto j = 0; j < A.length - 1; j++)
    {
        if (A[j] <= x)
        {
            i++;
            A[i].swap(A[j]);
        }
    }
    A[i + 1].swap(A[A.length - 1]);
    return i + 1;
}
void quick_sort(T)(T A)
{
    if (A.length >= 2)
    {
        auto q = partition(A);
        quick_sort(A[0..q]);
        quick_sort(A[q + 1..$]);
    }
}

void main()
{
    int[] a = readln().strip.split(' ').map!(x => x.to!int).array;
    auto count = a[0];
    auto cards = new Card[count];
    for (int i = 0; i < count; i++)
    {
        auto j = readln().strip.split(' ').array;
        auto k = j[0][0];
        auto l = j[1].to!int;
        cards[i].value = l;
        cards[i].suit = k;
    }
    auto cards2 = cards.dup;
    quick_sort(cards);
    writeln(cards2.sort.equal!((x, y) => x.suit == y.suit && x.value == y.value)(cards) ? "Stable" : "Not stable");
    
    for (int i = 0; i < count; i++)
    {
        writeln(cards[i].suit, " ", cards[i].value);
    }
}
