def partition(data, left, right):

    pivot = int(data[right][2:])

    i = left - 1

    for j in range(left, right):

        if int(data[j][2:]) <= pivot:

            i += 1

            data[i], data[j] = data[j], data[i]

    data[i+1], data[right] = data[right], data[i+1]

    return i+1



def quick_sort(data, left, right):

    if left < right:

        new_pivot = partition(data, left, right)

        quick_sort(data, left, new_pivot-1)

        quick_sort(data, new_pivot+1, right)



#for comparison

def merge(data, left, mid, right):

    n1 = mid - left

    n2 = right - mid

    L = data[left : mid]

    R = data[mid : right]

    L.append("  10000000000")

    R.append("  10000000000")

    i = 0

    j = 0

    for k in range(left, right):

        if int(L[i][2:]) <= int(R[j][2:]):

            data[k] = L[i]

            i += 1

        else:

            data[k] = R[j]

            j += 1



def merge_sort(data, left, right):

    if left + 1 < right:

        mid = (left + right) / 2

        merge_sort(data, left, mid)

        merge_sort(data, mid, right)

        merge(data, left, mid, right)



def main():

    num = input()

    pairs_quick = []

    pairs_check = []

    for i in range(int(num)):

        pair = input()

        pairs_quick.append(pair)

        pairs_check.append(pair)

    

    quick_sort(pairs_quick, 0, int(num)-1)

    merge_sort(pairs_check, 0, int(num))

    if pairs_quick == pairs_check:

        print("Stable")

    else:

        print("Not stable")



    print("\n".join(pairs_quick))

    #print "\n".join(pairs_check)



if __name__ == "__main__":

    main()
def partition(data, left, right):

    pivot = int(data[right][2:])

    i = left - 1

    for j in range(left, right):

        if int(data[j][2:]) <= pivot:

            i += 1

            data[i], data[j] = data[j], data[i]

    data[i+1], data[right] = data[right], data[i+1]

    return i+1



def quick_sort(data, left, right):

    if left < right:

        new_pivot = partition(data, left, right)

        quick_sort(data, left, new_pivot-1)

        quick_sort(data, new_pivot+1, right)



def main():

    num = input()

    pairs_quick = []

    pairs_check = []

    for i in range(int(num)):

        pair = input()

        pairs_quick.append(pair)

        pairs_check.append(pair)

    

    quick_sort(pairs_quick, 0, int(num)-1)

    pairs_check = sorted(pairs_check, key = lambda i:int(i[2:]))

    if pairs_quick == pairs_check:

        print("Stable")

    else:

        print("Not stable")



    print("\n".join(pairs_quick))



if __name__ == "__main__":

    main()
def partition(data, left, right):
    pivot = int(data[right][2:])
    i = left - 1
    for j in range(left, right):
        if int(data[j][2:]) <= pivot:
            i += 1
            data[i], data[j] = data[j], data[i]
    data[i + 1], data[right] = data[right], data[i + 1]
    return i + 1


def quick_sort(data, left, right):
    if left < right:
        new_pivot = partition(data, left, right)
        quick_sort(data, left, new_pivot - 1)
        quick_sort(data, new_pivot + 1, right)


# for comparison
def merge(data, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = data[left:mid]
    R = data[mid:right]
    L.append("  10000000000")
    R.append("  10000000000")
    i = 0
    j = 0
    for k in range(left, right):
        if int(L[i][2:]) <= int(R[j][2:]):
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1


def merge_sort(data, left, right):
    if left + 1 < right:
        mid = (left + right) / 2
        merge_sort(data, left, mid)
        merge_sort(data, mid, right)
        merge(data, left, mid, right)


def main():
    num = input()
    pairs_quick = []
    pairs_check = []
    for i in range(int(num)):
        pair = input()
        pairs_quick.append(pair)
        pairs_check.append(pair)
    quick_sort(pairs_quick, 0, int(num) - 1)
    merge_sort(pairs_check, 0, int(num))
    if pairs_quick == pairs_check:
        print("Stable")
    else:
        print("Not stable")
    print("\n".join(pairs_quick))
    # print "\n".join(pairs_check)


if __name__ == "__main__":
    main()

def partition(data, left, right):
    pivot = int(data[right][2:])
    i = left - 1
    for j in range(left, right):
        if int(data[j][2:]) <= pivot:
            i += 1
            data[i], data[j] = data[j], data[i]
    data[i + 1], data[right] = data[right], data[i + 1]
    return i + 1


def quick_sort(data, left, right):
    if left < right:
        new_pivot = partition(data, left, right)
        quick_sort(data, left, new_pivot - 1)
        quick_sort(data, new_pivot + 1, right)


def main():
    num = input()
    pairs_quick = []
    pairs_check = []
    for i in range(int(num)):
        pair = input()
        pairs_quick.append(pair)
        pairs_check.append(pair)
    quick_sort(pairs_quick, 0, int(num) - 1)
    pairs_check = sorted(pairs_check, key=lambda i: int(i[2:]))
    if pairs_quick == pairs_check:
        print("Stable")
    else:
        print("Not stable")
    print("\n".join(pairs_quick))


if __name__ == "__main__":
    main()

-# for comparison -def merge(data, left, mid, right): -    n1 = mid - left -    n2 = right - mid -    L = data[left:mid] -    R = data[mid:right] -    L.append("  10000000000") -    R.append("  10000000000") -    i = 0 -    j = 0 -    for k in range(left, right): -        if int(L[i][2:]) <= int(R[j][2:]): -            data[k] = L[i] -            i += 1 -        else: -            data[k] = R[j] -            j += 1 - - -def merge_sort(data, left, right): -    if left + 1 < right: -        mid = (left + right) / 2 -        merge_sort(data, left, mid) -        merge_sort(data, mid, right) -        merge(data, left, mid, right) - - -    merge_sort(pairs_check, 0, int(num)) +    pairs_check = sorted(pairs_check, key=lambda i: int(i[2:])) -    # print "\n".join(pairs_check)