import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison, std.algorithm.mutation;


struct Card
{
    char c;
    int n;
    string toString()
    {
        return format("%c %d\n", c, n);
    }
}
void main()
{
    int N = readln().strip.to!int;
    Card[] list;
    char[][int] hash;
    foreach(i; 0..N)
    {
        char c;
        int n;
        readf(" %c %d", &c, &n);
        list ~= Card(c, n);
        hash[n] ~= c;
    }
    sort(list);
    bool isStable=true;
    foreach(e; list)
    {
        if(e.c != hash[e.n].front)
        {
            isStable = false;
        }
        hash[e.n].popFront();
    }
    writeln(isStable?"Stable":"Not stable");
    write(format("%-(%s%)", list.map!(a=>a.toString())));
}

void sort(Card[] list)
{
    if(list.length == 1 || list.length == 0)
    {
        return;
    }
    auto key = list[0];
    int li = 0;
    foreach(i; 0..list.length)
    {
        if(key.n > list[i].n)
        {
            auto tmp = list[i];
            list[i] = list[li];
            list[li] = tmp;
            li++;
        }
    }
    sort(list[0..li]);
    sort(list[(li+1)..$]);
}

sizediff_t minIndex(alias pred="a<b", R) (R list)
    if(isForwardRange!R && !isInfinite!R && is(typeof(binaryFun!pred(list.front, list.front))))
{
    assert(!list.empty);
    typeof(list.front) min = list.front;
    sizediff_t minPos;
    sizediff_t curPos;
    for(list.popFront(); !list.empty; list.popFront())
    {
        curPos++;

        if(binaryFun!pred(list.front, min))
        {
            min = list.front;
            minPos = curPos;
        }
    }
    return minPos;
}

