import sys



class card:

    def __init__(self, types, value):

        self.types = types

        self.value = value



def quickSort(A, p, r):

    if p < r:

        q = partition(A, p, r)

        quickSort(A, p, q - 1)

        quickSort(A, q + 1, r)



def partition(A, p, r):

    x = A[r].value

    i = p - 1

    for j in range(p, r):

        if A[j].value <= x:

            i += 1

            swap(A, i, j)

    swap(A, i + 1, r)



    return i + 1



def swap(array, i, j):

    tmp = array[i]

    array[i] = array[j]

    array[j] = tmp



def checkStable(origin, sorted, N):

    for i in range(0, N - 1):

        if sorted[i].value == sorted[i + 1].value:

            if origin.index(sorted[i]) > origin.index(sorted[i + 1]):

                return False

    return True



if __name__ == "__main__":

    lines = sys.stdin.readlines()

    del lines[0]

    A = [card(c[0], int(c[2:])) for c in lines]

    origin = A[:]

    quickSort(A, 0, len(A) - 1)

    if checkStable(origin, A, len(A)):

        print("Stable")

    else:

        print("Not stable")

    for a in A:

        print(a.types + " " + str(a.value))
import sys



class card:

    def __init__(self, suit, num):

        self.suit = suit

        self.num = num



def quickSort(A, p, r):

    if p < r:

        q = partition(A, p, r)

        quickSort(A, p, q - 1)

        quickSort(A, q + 1, r)



def partition(A, p, r):

    x = A[r].num

    i = p - 1

    for j in range(p, r):

        if A[j].num <= x:

            i += 1

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

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



    return i + 1



def checkStable(origin, sorted):

    for i in range(0, len(origin) - 1):

        if sorted[i].num == sorted[i + 1].num:

            if origin.index(sorted[i]) > origin.index(sorted[i + 1]):

                return False

    return True



if __name__ == "__main__":

    lines = sys.stdin.readlines()

    del lines[0]

    A = [card(c[0], int(c[2:])) for c in lines]

    origin = A[:]

    quickSort(A, 0, len(A) - 1)



    if checkStable(origin, A):

        print("Stable")

    else:

        print("Not stable")



    for a in A:

        print(a.suit, str(a.num))
import sys


class card:
    def __init__(self, types, value):
        self.types = types
        self.value = value


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


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


def swap(array, i, j):
    tmp = array[i]
    array[i] = array[j]
    array[j] = tmp


def checkStable(origin, sorted, N):
    for i in range(0, N - 1):
        if sorted[i].value == sorted[i + 1].value:
            if origin.index(sorted[i]) > origin.index(sorted[i + 1]):
                return False
    return True


if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]
    A = [card(c[0], int(c[2:])) for c in lines]
    origin = A[:]
    quickSort(A, 0, len(A) - 1)
    if checkStable(origin, A, len(A)):
        print("Stable")
    else:
        print("Not stable")
    for a in A:
        print(a.types + " " + str(a.value))

import sys


class card:
    def __init__(self, suit, num):
        self.suit = suit
        self.num = num


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


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


def checkStable(origin, sorted):
    for i in range(0, len(origin) - 1):
        if sorted[i].num == sorted[i + 1].num:
            if origin.index(sorted[i]) > origin.index(sorted[i + 1]):
                return False
    return True


if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]
    A = [card(c[0], int(c[2:])) for c in lines]
    origin = A[:]
    quickSort(A, 0, len(A) - 1)
    if checkStable(origin, A):
        print("Stable")
    else:
        print("Not stable")
    for a in A:
        print(a.suit, str(a.num))

-    def __init__(self, types, value): -        self.types = types -        self.value = value +    def __init__(self, suit, num): +        self.suit = suit +        self.num = num -    x = A[r].value +    x = A[r].num -        if A[j].value <= x: +        if A[j].num <= x: -            swap(A, i, j) -    swap(A, i + 1, r) +            A[i], A[j] = A[j], A[i] +    A[i + 1], A[r] = A[r], A[i + 1] -def swap(array, i, j): -    tmp = array[i] -    array[i] = array[j] -    array[j] = tmp - - -def checkStable(origin, sorted, N): -    for i in range(0, N - 1): -        if sorted[i].value == sorted[i + 1].value: +def checkStable(origin, sorted): +    for i in range(0, len(origin) - 1): +        if sorted[i].num == sorted[i + 1].num: -    if checkStable(origin, A, len(A)): +    if checkStable(origin, A): -        print(a.types + " " + str(a.value)) +        print(a.suit, str(a.num))