MARK = 0
NUMBER = 1


def bubble_sort(A):
    for i in range(len(A)-1):
        for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j)


def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
        if mini != i:
            swap(A, mini, i)


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


amount = int(input())
cards = input().split()  # list of cards (ex:[H2 S8])
isStable_selection = True

# make tuple of mark and number
for i in range(amount):
    cards[i] = tuple([cards[i][MARK], int(cards[i][NUMBER])])

cards_bubble = list(cards)
cards_selection = list(cards)

bubble_sort(cards_bubble)
selection_sort(cards_selection)

# judge stable or not (bubble sort is stable)
if cards_bubble == cards_selection:
    isStable_selection = True
else:
    isStable_selection = False

print(*[cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER])
        for i in range(amount)])
print("Stable")

print(*[cards_selection[i][MARK] + str(cards_selection[i][NUMBER])
        for i in range(amount)])
if isStable_selection:
    print("Stable")
else:
    print("Not stable") MARK = 0 MARK 0 NUMBER = 1 NUMBER 1 def bubble_sort(A):
    for i in range(len(A)-1):
        for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j) bubble_sort for i in range(len(A)-1):
        for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j) i range(len(A)-1) range len(A)-1 len(A) len A 1 for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j) j reversed(range(i+1, len(A))) reversed range(i+1, len(A)) range i+1 i 1 len(A) len A if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j) A[j][NUMBER] < A[j - 1][NUMBER] A[j][NUMBER] [j] A j NUMBER A[j - 1][NUMBER] [j - 1] A j - 1 j 1 NUMBER swap(A, j-1, j) swap A j-1 j 1 j A A def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
        if mini != i:
            swap(A, mini, i) selection_sort for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
        if mini != i:
            swap(A, mini, i) i range(len(A)) range len(A) len A mini = i mini i for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
         j range(i, len(A)) range i len(A) len A if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
         A[j][NUMBER] < A[mini][NUMBER] A[j][NUMBER] [j] A j NUMBER A[mini][NUMBER] [mini] A mini NUMBER mini = j mini j if mini != i:
            swap(A, mini, i) mini != i mini i swap(A, mini, i) swap A mini i A A def swap(A, i, j):
    tmp = A[j]
    A[j] = A[i]
    A[i] = tmp swap tmp = A[j] tmp A[j] A j A[j] = A[i] A[j] A j A[i] A i A[i] = tmp A[i] A i tmp A A i i j j amount = int(input()) amount int(input()) int input() input cards = input().split() cards input().split() ().split () input split isStable_selection = True isStable_selection True for i in range(amount):
    cards[i] = tuple([cards[i][MARK], int(cards[i][NUMBER])]) i range(amount) range amount cards[i] = tuple([cards[i][MARK], int(cards[i][NUMBER])]) cards[i] cards i tuple([cards[i][MARK], int(cards[i][NUMBER])]) tuple [cards[i][MARK], int(cards[i][NUMBER])] cards[i][MARK] [i] cards i MARK int(cards[i][NUMBER]) int cards[i][NUMBER] [i] cards i NUMBER cards_bubble = list(cards) cards_bubble list(cards) list cards cards_selection = list(cards) cards_selection list(cards) list cards bubble_sort(cards_bubble) bubble_sort cards_bubble selection_sort(cards_selection) selection_sort cards_selection if cards_bubble == cards_selection:
    isStable_selection = True
else:
    isStable_selection = False cards_bubble == cards_selection cards_bubble cards_selection isStable_selection = True isStable_selection True isStable_selection = False isStable_selection False cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER])
        for i in range(amount) for i in range(amount) i range(amount) range amount for i in range(amount) cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER]) cards_bubble[i][MARK] [i] cards_bubble i MARK str(cards_bubble[i][NUMBER]) str cards_bubble[i][NUMBER] [i] cards_bubble i NUMBER print(*[cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER])
        for i in range(amount)]) print *[cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER])
        for i in range(amount)] [cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER])
        for i in range(amount)] print("Stable") print "Stable" cards_selection[i][MARK] + str(cards_selection[i][NUMBER])
        for i in range(amount) for i in range(amount) i range(amount) range amount for i in range(amount) cards_selection[i][MARK] + str(cards_selection[i][NUMBER]) cards_selection[i][MARK] [i] cards_selection i MARK str(cards_selection[i][NUMBER]) str cards_selection[i][NUMBER] [i] cards_selection i NUMBER print(*[cards_selection[i][MARK] + str(cards_selection[i][NUMBER])
        for i in range(amount)]) print *[cards_selection[i][MARK] + str(cards_selection[i][NUMBER])
        for i in range(amount)] [cards_selection[i][MARK] + str(cards_selection[i][NUMBER])
        for i in range(amount)] if isStable_selection:
    print("Stable")
else:
    print("Not stable") isStable_selection print("Stable") print "Stable" print("Not stable") print "Not stable" cards_selection = list(cards) list(cards) cards_selection cards = input().split() input().split() cards def bubble_sort(A):
    for i in range(len(A)-1):
        for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j) def bubble_sort(A):
    for i in range(len(A)-1):
        for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j) bubble_sort NUMBER = 1 1 NUMBER def swap(A, i, j):
    tmp = A[j]
    A[j] = A[i]
    A[i] = tmp def swap(A, i, j):
    tmp = A[j]
    A[j] = A[i]
    A[i] = tmp swap isStable_selection = True True isStable_selection isStable_selection = False False isStable_selection def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
        if mini != i:
            swap(A, mini, i) def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
        if mini != i:
            swap(A, mini, i) selection_sort amount = int(input()) int(input()) amount cards_bubble = list(cards) list(cards) cards_bubble MARK = 0 0 MARK isStable_selection = True True isStable_selection
MARK = 0
NUMBER = 1


def bubble_sort(A):
    for i in range(len(A)-1):
        for j in reversed(range(i+1, len(A))):
            if A[j][NUMBER] < A[j - 1][NUMBER]:
                swap(A, j-1, j)


def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][NUMBER] < A[mini][NUMBER]:
                mini = j
        if mini != i:
            swap(A, mini, i)


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


amount = int(input())
cards = input().split()  # list of cards (ex:[H2 S8])
isStable_selection = True

# make tuple of mark and number
for i in range(amount):
    cards[i] = tuple([cards[i][MARK], int(cards[i][NUMBER])])

cards_bubble = list(cards)
cards_selection = list(cards)

bubble_sort(cards_bubble)
selection_sort(cards_selection)

# judge stable or not (bubble sort is stable)
if cards_bubble == cards_selection:
    isStable_selection = True
else:
    isStable_selection = False

print(*[cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER])
        for i in range(amount)])
print("Stable")

print(*[cards_selection[i][MARK] + str(cards_selection[i][NUMBER])
        for i in range(amount)])
if isStable_selection:
    print("Stable")
else:
    print("Not stable")