import copy



n = int(input())

cards = []

for i in range(n):

    suit,num = input().strip().split(' ')

    num = int(num)

    cards.append((suit,num))



def quick_sort(S,p,r):

    if p < r:

        q = partition(S,p,r)

        quick_sort(S,p,q-1)

        quick_sort(S,q+1,r)



def partition(S,p,r):

    x = S[r][1]

    i = p-1

    for j in range(p,r):

        if S[j][1] <= x:

            i += 1

            S[j],S[i]=S[i],S[j]

    S[r],S[i+1]=S[i+1],S[r]

    return i+1



def merge_sort(S):

    if len(S) <= 1:

        return S

    S1,S2 = split(S)

    return merge(merge_sort(S1),merge_sort(S2))



def split(S):

    mid = len(S)/2

    return S[:mid],S[mid:]



def merge(S1,S2):

    S = []

    S1.append(('SENTINEL',100000000000))

    S2.append(('SENTINEL',100000000000))

    i = 0

    j = 0

    for k in range(len(S1)+len(S2)-2):

        if S1[i][1] <= S2[j][1]:

            S.append(S1[i])

            i += 1

        else:

            S.append(S2[j])

            j += 1

    return S







cards2 = copy.copy(cards)

quick_sort(cards,0,len(cards)-1)

cards2 = merge_sort(cards2)

flag = True

for i in range(len(cards)):

    if cards[i] != cards2[i]:

        print("Not stable")

        flag = False

        break

if flag: print("Stable")

for suit,num in cards:

    print(suit,num)
def sort(a, p, r):

    if p < r:

        q = partition(a, p, r)

        sort(a, p, q-1)

        sort(a, q+1, r)





def partition(a, p, r):

    pivot = a[r]

    i = p-1

    for j in range(p, r):

        if compare(pivot, a[j]) >= 0:

            i += 1

            a[i], a[j] = a[j], a[i]

    a[r], a[i+1] = a[i+1], a[r]

    return i+1



def compare(a,b):

    if a[0] > b[0]:

        return 1

    elif a[0] < b[0]:

        return -1

    else:

        return 0



n = int(input())

a = []

suits = {}

for _ in range(n):

    suit, number = input().split(' ')

    number = int(number)

    a.append((number, suit))

    if number not in suits:

        suits[number] = []

    suits[number].append(suit)



sort(a, 0, len(a)-1)



flag = True

for number, suit in a:

    correct_suit = suits[number].pop(0)

    if suit != correct_suit:

        flag = False

        break



if flag:

    print("Stable")

else:

    print("Not stable")



for number, suit in a:

    print(suit, number)
import copy

n = int(input())
cards = []
for i in range(n):
    suit, num = input().strip().split(" ")
    num = int(num)
    cards.append((suit, num))


def quick_sort(S, p, r):
    if p < r:
        q = partition(S, p, r)
        quick_sort(S, p, q - 1)
        quick_sort(S, q + 1, r)


def partition(S, p, r):
    x = S[r][1]
    i = p - 1
    for j in range(p, r):
        if S[j][1] <= x:
            i += 1
            S[j], S[i] = S[i], S[j]
    S[r], S[i + 1] = S[i + 1], S[r]
    return i + 1


def merge_sort(S):
    if len(S) <= 1:
        return S
    S1, S2 = split(S)
    return merge(merge_sort(S1), merge_sort(S2))


def split(S):
    mid = len(S) / 2
    return S[:mid], S[mid:]


def merge(S1, S2):
    S = []
    S1.append(("SENTINEL", 100000000000))
    S2.append(("SENTINEL", 100000000000))
    i = 0
    j = 0
    for k in range(len(S1) + len(S2) - 2):
        if S1[i][1] <= S2[j][1]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S


cards2 = copy.copy(cards)
quick_sort(cards, 0, len(cards) - 1)
cards2 = merge_sort(cards2)
flag = True
for i in range(len(cards)):
    if cards[i] != cards2[i]:
        print("Not stable")
        flag = False
        break
if flag:
    print("Stable")
for suit, num in cards:
    print(suit, num)

def sort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        sort(a, p, q - 1)
        sort(a, q + 1, r)


def partition(a, p, r):
    pivot = a[r]
    i = p - 1
    for j in range(p, r):
        if compare(pivot, a[j]) >= 0:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[r], a[i + 1] = a[i + 1], a[r]
    return i + 1


def compare(a, b):
    if a[0] > b[0]:
        return 1
    elif a[0] < b[0]:
        return -1
    else:
        return 0


n = int(input())
a = []
suits = {}
for _ in range(n):
    suit, number = input().split(" ")
    number = int(number)
    a.append((number, suit))
    if number not in suits:
        suits[number] = []
    suits[number].append(suit)
sort(a, 0, len(a) - 1)
flag = True
for number, suit in a:
    correct_suit = suits[number].pop(0)
    if suit != correct_suit:
        flag = False
        break
if flag:
    print("Stable")
else:
    print("Not stable")
for number, suit in a:
    print(suit, number)

-import copy - -n = int(input()) -cards = [] -for i in range(n): -    suit, num = input().strip().split(" ") -    num = int(num) -    cards.append((suit, num)) +def sort(a, p, r): +    if p < r: +        q = partition(a, p, r) +        sort(a, p, q - 1) +        sort(a, q + 1, r) -def quick_sort(S, p, r): -    if p < r: -        q = partition(S, p, r) -        quick_sort(S, p, q - 1) -        quick_sort(S, q + 1, r) - - -def partition(S, p, r): -    x = S[r][1] +def partition(a, p, r): +    pivot = a[r] -        if S[j][1] <= x: +        if compare(pivot, a[j]) >= 0: -            S[j], S[i] = S[i], S[j] -    S[r], S[i + 1] = S[i + 1], S[r] +            a[i], a[j] = a[j], a[i] +    a[r], a[i + 1] = a[i + 1], a[r] -def merge_sort(S): -    if len(S) <= 1: -        return S -    S1, S2 = split(S) -    return merge(merge_sort(S1), merge_sort(S2)) +def compare(a, b): +    if a[0] > b[0]: +        return 1 +    elif a[0] < b[0]: +        return -1 +    else: +        return 0 -def split(S): -    mid = len(S) / 2 -    return S[:mid], S[mid:] - - -def merge(S1, S2): -    S = [] -    S1.append(("SENTINEL", 100000000000)) -    S2.append(("SENTINEL", 100000000000)) -    i = 0 -    j = 0 -    for k in range(len(S1) + len(S2) - 2): -        if S1[i][1] <= S2[j][1]: -            S.append(S1[i]) -            i += 1 -        else: -            S.append(S2[j]) -            j += 1 -    return S - - -cards2 = copy.copy(cards) -quick_sort(cards, 0, len(cards) - 1) -cards2 = merge_sort(cards2) +n = int(input()) +a = [] +suits = {} +for _ in range(n): +    suit, number = input().split(" ") +    number = int(number) +    a.append((number, suit)) +    if number not in suits: +        suits[number] = [] +    suits[number].append(suit) +sort(a, 0, len(a) - 1) -for i in range(len(cards)): -    if cards[i] != cards2[i]: -        print("Not stable") +for number, suit in a: +    correct_suit = suits[number].pop(0) +    if suit != correct_suit: -for suit, num in cards: -    print(suit, num) +else: +    print("Not stable") +for number, suit in a: +    print(suit, number)