n = int(input())
card1 = list(input().split())
card2 = [i for i in card1]
def bubbleSort(c1:list, n:int):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
    return c1

def selectionSort(c2:list, n:int):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
        c2[i], c2[minj] = c2[minj], c2[i]
    return c2

bubblesort = bubbleSort(card1, n)
selectionsort = selectionSort(card2, n)

flag = 0
for i in range(n):
    if bubblesort[i] != selectionsort[i]:
        flag = 1

print(" ".join(bubblesort))
print("Stable")
print(" ".join(selectionsort))
if flag:
    print("Not stable")
else:
    print("Stable")
 n = int(input()) n int(input()) int input() input card1 = list(input().split()) card1 list(input().split()) list input().split() ().split () input split i for i in card1 for i in card1 i card1 for i in card1 i card2 = [i for i in card1] card2 [i for i in card1] def bubbleSort(c1:list, n:int):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
    return c1 bubbleSort for i in range(n):
        for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
     i range(n) range n for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
     j range(n-1, i, -1) range n-1 n 1 i -1 if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
     c1[j][1] < c1[j-1][1] c1[j][1] [j] c1 j 1 c1[j-1][1] [j-1] c1 j-1 j 1 1 c1[j], c1[j-1] = c1[j-1], c1[j] c1[j] c1 j c1[j-1] c1 j-1 j 1 c1[j-1] c1 j-1 j 1 c1[j] c1 j return c1 c1 c1:list c1 n:int n def selectionSort(c2:list, n:int):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
        c2[i], c2[minj] = c2[minj], c2[i]
    return c2 selectionSort for i in range(n):
        minj = i
        for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
        c2[i], c2[minj] = c2[minj], c2[i]
     i range(n) range n minj = i minj i for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
         j range(i, n) range i n if c2[j][1] < c2[minj][1]:
                minj = j
         c2[j][1] < c2[minj][1] c2[j][1] [j] c2 j 1 c2[minj][1] [minj] c2 minj 1 minj = j minj j c2[i], c2[minj] = c2[minj], c2[i] c2[i] c2 i c2[minj] c2 minj c2[minj] c2 minj c2[i] c2 i return c2 c2 c2:list c2 n:int n bubblesort = bubbleSort(card1, n) bubblesort bubbleSort(card1, n) bubbleSort card1 n selectionsort = selectionSort(card2, n) selectionsort selectionSort(card2, n) selectionSort card2 n flag = 0 flag 0 for i in range(n):
    if bubblesort[i] != selectionsort[i]:
        flag = 1 i range(n) range n if bubblesort[i] != selectionsort[i]:
        flag = 1 bubblesort[i] != selectionsort[i] bubblesort[i] bubblesort i selectionsort[i] selectionsort i flag = 1 flag 1 print(" ".join(bubblesort)) print " ".join(bubblesort) " ".join " " join bubblesort print("Stable") print "Stable" print(" ".join(selectionsort)) print " ".join(selectionsort) " ".join " " join selectionsort if flag:
    print("Not stable")
else:
    print("Stable") flag print("Not stable") print "Not stable" print("Stable") print "Stable" card2 = [i for i in card1] [i for i in card1] card2 bubblesort = bubbleSort(card1, n) bubbleSort(card1, n) bubblesort flag = 0 0 flag n = int(input()) int(input()) n flag = 1 1 flag card1 = list(input().split()) list(input().split()) card1 def bubbleSort(c1:list, n:int):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
    return c1 def bubbleSort(c1:list, n:int):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
    return c1 bubbleSort selectionsort = selectionSort(card2, n) selectionSort(card2, n) selectionsort def selectionSort(c2:list, n:int):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
        c2[i], c2[minj] = c2[minj], c2[i]
    return c2 def selectionSort(c2:list, n:int):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
        c2[i], c2[minj] = c2[minj], c2[i]
    return c2 selectionSort
n = int(input())
card1 = list(input().split())
card2 = [i for i in card1]
def bubbleSort(c1:list, n:int):
    for i in range(n):
        for j in range(n-1, i, -1):
            if c1[j][1] < c1[j-1][1]:
                c1[j], c1[j-1] = c1[j-1], c1[j]
    return c1

def selectionSort(c2:list, n:int):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c2[j][1] < c2[minj][1]:
                minj = j
        c2[i], c2[minj] = c2[minj], c2[i]
    return c2

bubblesort = bubbleSort(card1, n)
selectionsort = selectionSort(card2, n)

flag = 0
for i in range(n):
    if bubblesort[i] != selectionsort[i]:
        flag = 1

print(" ".join(bubblesort))
print("Stable")
print(" ".join(selectionsort))
if flag:
    print("Not stable")
else:
    print("Stable")

