import copy
import sys
input = sys.stdin.readline


def bubble_sort(A):
    for _ in range(len(A)):
        for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
    return A


def selection_sort(A):
    for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
        A[i], A[_min] = A[_min], A[i]
    return A


def main():
    _ = input()
    A = input().strip().split()
    b_A = copy.deepcopy(A)
    bubble_sort(b_A)
    print(" ".join(b_A))
    print("Stable")

    selection_sort(A)
    print(" ".join(A))
    for b, s in zip(b_A, A):
        if b == s:
            continue
        else:
            print("Not stable")
            return
    print("Stable")
    return


if __name__ == "__main__":
    main()
 import copy copy import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def bubble_sort(A):
    for _ in range(len(A)):
        for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
    return A bubble_sort for _ in range(len(A)):
        for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
     _ range(len(A)) range len(A) len A for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
     i range(1, len(A))[::-1] (1, len(A)) range 1 len(A) len A ::-1 -1 if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
     int(A[i][1:]) < int(A[i - 1][1:]) int(A[i][1:]) int A[i][1:] [i] A i 1: 1 int(A[i - 1][1:]) int A[i - 1][1:] [i - 1] A i - 1 i 1 1: 1 A[i], A[i - 1] = A[i - 1], A[i] A[i] A i A[i - 1] A i - 1 i 1 A[i - 1] A i - 1 i 1 A[i] A i return A A A A def selection_sort(A):
    for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
        A[i], A[_min] = A[_min], A[i]
    return A selection_sort for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
        A[i], A[_min] = A[_min], A[i]
     i range(len(A)) range len(A) len A _min = i _min i for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
         j range(i, len(A)) range i len(A) len A if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
         int(A[j][1:]) < int(A[_min][1:]) int(A[j][1:]) int A[j][1:] [j] A j 1: 1 int(A[_min][1:]) int A[_min][1:] [_min] A _min 1: 1 _min = j _min j A[i], A[_min] = A[_min], A[i] A[i] A i A[_min] A _min A[_min] A _min A[i] A i return A A A A def main():
    _ = input()
    A = input().strip().split()
    b_A = copy.deepcopy(A)
    bubble_sort(b_A)
    print(" ".join(b_A))
    print("Stable")

    selection_sort(A)
    print(" ".join(A))
    for b, s in zip(b_A, A):
        if b == s:
            continue
        else:
            print("Not stable")
            return
    print("Stable")
    return main _ = input() _ input() input A = input().strip().split() A input().strip().split() ().strip().split ().strip() ().strip () input strip split b_A = copy.deepcopy(A) b_A copy.deepcopy(A) copy.deepcopy copy deepcopy A bubble_sort(b_A) bubble_sort b_A print(" ".join(b_A)) print " ".join(b_A) " ".join " " join b_A print("Stable") print "Stable" selection_sort(A) selection_sort A print(" ".join(A)) print " ".join(A) " ".join " " join A for b, s in zip(b_A, A):
        if b == s:
            continue
        else:
            print("Not stable")
            return
     b s zip(b_A, A) zip b_A A if b == s:
            continue
        else:
            print("Not stable")
            return
     b == s b s continue print("Not stable") print "Not stable" return print("Stable") print "Stable" return if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    _ = input()
    A = input().strip().split()
    b_A = copy.deepcopy(A)
    bubble_sort(b_A)
    print(" ".join(b_A))
    print("Stable")

    selection_sort(A)
    print(" ".join(A))
    for b, s in zip(b_A, A):
        if b == s:
            continue
        else:
            print("Not stable")
            return
    print("Stable")
    return def main():
    _ = input()
    A = input().strip().split()
    b_A = copy.deepcopy(A)
    bubble_sort(b_A)
    print(" ".join(b_A))
    print("Stable")

    selection_sort(A)
    print(" ".join(A))
    for b, s in zip(b_A, A):
        if b == s:
            continue
        else:
            print("Not stable")
            return
    print("Stable")
    return main def selection_sort(A):
    for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
        A[i], A[_min] = A[_min], A[i]
    return A def selection_sort(A):
    for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
        A[i], A[_min] = A[_min], A[i]
    return A selection_sort input = sys.stdin.readline sys.stdin.readline input def bubble_sort(A):
    for _ in range(len(A)):
        for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
    return A def bubble_sort(A):
    for _ in range(len(A)):
        for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
    return A bubble_sort
import copy
import sys
input = sys.stdin.readline


def bubble_sort(A):
    for _ in range(len(A)):
        for i in range(1, len(A))[::-1]:
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
    return A


def selection_sort(A):
    for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if int(A[j][1:]) < int(A[_min][1:]):
                _min = j
        A[i], A[_min] = A[_min], A[i]
    return A


def main():
    _ = input()
    A = input().strip().split()
    b_A = copy.deepcopy(A)
    bubble_sort(b_A)
    print(" ".join(b_A))
    print("Stable")

    selection_sort(A)
    print(" ".join(A))
    for b, s in zip(b_A, A):
        if b == s:
            continue
        else:
            print("Not stable")
            return
    print("Stable")
    return


if __name__ == "__main__":
    main()

