def bubbleSort(cards):
    for i, _ in enumerate(cards):
        for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    return cards
    
def selectionSort(cards):
    for i in range(len(cards)):
        min_j = i
        for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        cards[i], cards[min_j] = cards[min_j], cards[i]
    return cards
    
N = int(input())
A = input().split()

temp = A.copy()
bs = bubbleSort(temp)

temp = A.copy()
ss = selectionSort(temp)

print(' '.join(bs))
print('Stable')
print(' '.join(ss))
if [a[:1] for a in bs] == [a[:1] for a in ss]:
    print('Stable')
else:
    print('Not stable') def bubbleSort(cards):
    for i, _ in enumerate(cards):
        for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    return cards
     bubbleSort for i, _ in enumerate(cards):
        for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
     i _ enumerate(cards) enumerate cards for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
     j range(len(cards) -1, i, -1) range len(cards) -1 len(cards) len cards 1 i -1 if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
     int(cards[j][1]) <  int(cards[j-1][1]) int(cards[j][1]) int cards[j][1] [j] cards j 1 int(cards[j-1][1]) int cards[j-1][1] [j-1] cards j-1 j 1 1 cards[j], cards[j - 1] = cards[j - 1], cards[j] cards[j] cards j cards[j - 1] cards j - 1 j 1 cards[j - 1] cards j - 1 j 1 cards[j] cards j return cards cards cards cards def selectionSort(cards):
    for i in range(len(cards)):
        min_j = i
        for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        cards[i], cards[min_j] = cards[min_j], cards[i]
    return cards
     selectionSort for i in range(len(cards)):
        min_j = i
        for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        cards[i], cards[min_j] = cards[min_j], cards[i]
     i range(len(cards)) range len(cards) len cards min_j = i min_j i for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
         j range(i, len(cards)) range i len(cards) len cards if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
         int(cards[j][1]) < int(cards[min_j][1]) int(cards[j][1]) int cards[j][1] [j] cards j 1 int(cards[min_j][1]) int cards[min_j][1] [min_j] cards min_j 1 min_j = j min_j j cards[i], cards[min_j] = cards[min_j], cards[i] cards[i] cards i cards[min_j] cards min_j cards[min_j] cards min_j cards[i] cards i return cards cards cards cards N = int(input()) N int(input()) int input() input A = input().split() A input().split() ().split () input split temp = A.copy() temp A.copy() A.copy A copy bs = bubbleSort(temp) bs bubbleSort(temp) bubbleSort temp temp = A.copy() temp A.copy() A.copy A copy ss = selectionSort(temp) ss selectionSort(temp) selectionSort temp print(' '.join(bs)) print ' '.join(bs) ' '.join ' ' join bs print('Stable') print 'Stable' print(' '.join(ss)) print ' '.join(ss) ' '.join ' ' join ss if [a[:1] for a in bs] == [a[:1] for a in ss]:
    print('Stable')
else:
    print('Not stable') [a[:1] for a in bs] == [a[:1] for a in ss] [a[:1] for a in bs] [a[:1] for a in ss] print('Stable') print 'Stable' print('Not stable') print 'Not stable' ss = selectionSort(temp) selectionSort(temp) ss N = int(input()) int(input()) N A = input().split() input().split() A def selectionSort(cards):
    for i in range(len(cards)):
        min_j = i
        for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        cards[i], cards[min_j] = cards[min_j], cards[i]
    return cards
     def selectionSort(cards):
    for i in range(len(cards)):
        min_j = i
        for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        cards[i], cards[min_j] = cards[min_j], cards[i]
    return cards
     selectionSort bs = bubbleSort(temp) bubbleSort(temp) bs temp = A.copy() A.copy() temp temp = A.copy() A.copy() temp def bubbleSort(cards):
    for i, _ in enumerate(cards):
        for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    return cards
     def bubbleSort(cards):
    for i, _ in enumerate(cards):
        for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    return cards
     bubbleSort
def bubbleSort(cards):
    for i, _ in enumerate(cards):
        for j in range(len(cards) -1, i, -1):
            if int(cards[j][1]) <  int(cards[j-1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    return cards
    
def selectionSort(cards):
    for i in range(len(cards)):
        min_j = i
        for j in range(i, len(cards)):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        cards[i], cards[min_j] = cards[min_j], cards[i]
    return cards
    
N = int(input())
A = input().split()

temp = A.copy()
bs = bubbleSort(temp)

temp = A.copy()
ss = selectionSort(temp)

print(' '.join(bs))
print('Stable')
print(' '.join(ss))
if [a[:1] for a in bs] == [a[:1] for a in ss]:
    print('Stable')
else:
    print('Not stable')
