import copy



def partition(p, r):

    i = p

    for j in range(p, r):

        if A[r][1] >= A[j][1]:

            A[i], A[j] = A[j], A[i]

            i += 1

    A[r], A[i] = A[i], A[r]

    return i



def quick_sort(p, r):

    if p < r:

        q = partition(p, r)

        quick_sort(p, q-1)

        quick_sort(q+1, r)



def correct_same_num_suits(l, num, first, ele_cnt):

    suits = []

    for i in range(first, N):

        if num == l[i][1]:

            suits.append(l[i][0])

        if ele_cnt == len(suits):

            break

    return suits



def is_stable():

    idx = 0

    while idx < N-1:

        idx_incr_flg = True

        if A[idx][1] == A[idx+1][1]:

            num = A[idx][1]

            j = idx

            ele_cnt = 0

            while j < N and num == A[j][1]:

                ele_cnt += 1

                j += 1

            sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt)

            orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt)

            if sorted_suits != orig_suits:

                return False

            idx += len(sorted_suits)

            idx_incr_flg = False

        if idx_incr_flg:

            idx += 1

    return True





N = int(eval(input()))

A = []

for _ in range(N):

    suit, num = input().split()

    num = int(num)

    A.append([suit, num])

orig_list = copy.deepcopy(A)



quick_sort(0, N-1)



is_stable = is_stable()

if is_stable:

    print("Stable")

else:

    print("Not stable")



for card in A:

    print(("%s %d" % (card[0], card[1])))

import copy



def partition(p, r):

    i = p

    for j in range(p, r):

        if A[r][1] >= A[j][1]:

            A[i], A[j] = A[j], A[i]

            i += 1

    A[r], A[i] = A[i], A[r]

    return i



def quick_sort(p, r):

    if p < r:

        q = partition(p, r)

        quick_sort(p, q-1)

        quick_sort(q+1, r)



def correct_same_num_suits(l, num, first, ele_cnt):

    suits = []

    append_cnt = 0

    for i in range(first, N):

        if num == l[i][1]:

            suits.append(l[i][0])

            append_cnt += 1

        if ele_cnt == append_cnt:

            break

    return suits



def is_stable():

    idx = 0

    while idx < N-1:

        idx_incr_flg = True

        if A[idx][1] == A[idx+1][1]:

            num = A[idx][1]

            j = idx

            ele_cnt = 0

            while j < N and num == A[j][1]:

                ele_cnt += 1

                j += 1

            sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt)

            orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt)

            if sorted_suits != orig_suits:

                return False

            idx += len(sorted_suits)

            idx_incr_flg = False

        if idx_incr_flg:

            idx += 1

    return True





N = int(eval(input()))

A = []

for _ in range(N):

    suit, num = input().split()

    num = int(num)

    A.append([suit, num])

orig_list = copy.deepcopy(A)



quick_sort(0, N-1)



is_stable = is_stable()

if is_stable:

    print("Stable")

else:

    print("Not stable")



for card in A:

    print(("%s %d" % (card[0], card[1])))

import copy


def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i


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


def correct_same_num_suits(l, num, first, ele_cnt):
    suits = []
    for i in range(first, N):
        if num == l[i][1]:
            suits.append(l[i][0])
        if ele_cnt == len(suits):
            break
    return suits


def is_stable():
    idx = 0
    while idx < N - 1:
        idx_incr_flg = True
        if A[idx][1] == A[idx + 1][1]:
            num = A[idx][1]
            j = idx
            ele_cnt = 0
            while j < N and num == A[j][1]:
                ele_cnt += 1
                j += 1
            sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt)
            orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt)
            if sorted_suits != orig_suits:
                return False
            idx += len(sorted_suits)
            idx_incr_flg = False
        if idx_incr_flg:
            idx += 1
    return True


N = int(eval(input()))
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.deepcopy(A)
quick_sort(0, N - 1)
is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")
for card in A:
    print(("%s %d" % (card[0], card[1])))

import copy


def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i


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


def correct_same_num_suits(l, num, first, ele_cnt):
    suits = []
    append_cnt = 0
    for i in range(first, N):
        if num == l[i][1]:
            suits.append(l[i][0])
            append_cnt += 1
        if ele_cnt == append_cnt:
            break
    return suits


def is_stable():
    idx = 0
    while idx < N - 1:
        idx_incr_flg = True
        if A[idx][1] == A[idx + 1][1]:
            num = A[idx][1]
            j = idx
            ele_cnt = 0
            while j < N and num == A[j][1]:
                ele_cnt += 1
                j += 1
            sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt)
            orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt)
            if sorted_suits != orig_suits:
                return False
            idx += len(sorted_suits)
            idx_incr_flg = False
        if idx_incr_flg:
            idx += 1
    return True


N = int(eval(input()))
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.deepcopy(A)
quick_sort(0, N - 1)
is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")
for card in A:
    print(("%s %d" % (card[0], card[1])))

+    append_cnt = 0 -        if ele_cnt == len(suits): +            append_cnt += 1 +        if ele_cnt == append_cnt: