const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const merge = (arr1, arr2) => {
    if (arr1.length === 0) return arr2;
    if (arr2.length === 0) return arr1;
    const head1 = arr1[0];
    const tail1 = arr1.slice(1);
    const head2 = arr2[0];
    const tail2 = arr2.slice(1);

    if (head1[1] <= head2[1]) return [head1, ...merge(tail1, arr2)];
    else return [head2, ...merge(arr1, tail2)];
};

const msort = arr => {
    if (arr.length <= 1) return arr;
    const n = Math.floor(arr.length / 2);
    const t = arr.slice(0, n);
    const b = arr.slice(n);
    return merge(msort(t), msort(b));
};


const partition = arr => {
    const x = arr[arr.length-1][1];
    const result = [...arr];
    let i = -1;
    for (let j = 0; j < arr.length - 1; j++) {
        if (result[j][1] <= x) {
            i++;
            const tmp = result[i];
            result[i] = result[j];
            result[j] = tmp;
        }
    }
    const tmp = result[i+1];
    result[i+1] = result[arr.length-1];
    result[arr.length-1] = tmp;

    return [i+1, result];
}

const qsort = arr => {
    if (arr.length <= 1) return arr;
    const newArr = partition(arr);
    const mid = newArr[1][newArr[0]];
    const l = newArr[1].slice(0, newArr[0]);
    const r = newArr[1].slice(newArr[0]+1);
    return [...qsort(l), mid, ...qsort(r)];
};

const check = target => {
    for (let i = 1; i < target.length; i++) {
        if (target[i][1] === target[i-1][1] && target[i][2] > target[i-1][2]) {
            return false;
        }
    }
    return true;
};

const data = line.slice(1, parseInt(line[0])+1)
                 .map(x => x.split(' '))
                 .map((xs, i) => [xs[0], Number(xs[1]), i]);

const qsorted = qsort(data);

console.log(check(qsorted) ? 'Stable' : 'Not stable');
qsorted.map(x => x.slice(0, 2))
       .map(x => x.join(' '))
       .forEach(x => console.log(x));

