function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const n = Number(stdin.shift());
    const cards = stdin.map(e => {
        const c = e.split(' ');
        return {mark: c[0], num: Number(c[1])};
    });
    const copy = cards.slice();
    let isStable = true;
    quickSort(cards, 0, n - 1);

    let temp = 0;
    const unum = cards.filter(e => {
        if(temp !== e.num) {
            temp = e.num;
            return temp;
        }
    }).map(e => e.num);

    temp = 0;
    while(isStable && unum.length > temp) {
        const n = unum[temp];
        const initial = cards.filter(e => e.num === n).map(e => e.mark).join();
        const ini2  = copy.filter(e => e.num === n).map(e => e.mark).join();
        if(ini2 !== initial) {
            isStable  = false;
        }
        temp++;
    }

    console.log(isStable ? 'Stable' : 'Not stable');

    for(const card of cards) {
        console.log(card.mark, card.num);
    }
}

function quickSort(A, p, r) {
    if (p < r) {
        const q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}


function partition(A, p, r) {
    let lower = p - 1;
    const x = A[r];

    for (let i = p; i < r; i++) {
        if (A[i].num <= x.num) {
            lower++;
            let t = A[lower];
            A[lower] = A[i];
            A[i] = t;
        }
    }

    t = A[lower + 1];
    A[lower + 1] = A[r];
    A[r] = t;
    return lower + 1;
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));

