#coding:utf-8
#1_2_C

def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards

def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards

n = int(input())
cards = input().split()
copy = list(cards)

print(*BubbleSort(cards, n))
print("Stable")
print(*SelectionSort(copy, n))
print("Stable" if cards == copy else "Not stable") def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards BubbleSort for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
     i range(n) range n for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
     j range(n-1, i, -1) range n-1 n 1 i -1 if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
     cards[j][1] < cards[j-1][1] cards[j][1] [j] cards j 1 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 n n def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards SelectionSort for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
     i range(n) range n minj = i minj i for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
         j range(i, n) range i n if cards[minj][1] > cards[j][1]:
                minj = j
         cards[minj][1] > cards[j][1] cards[minj][1] [minj] cards minj 1 cards[j][1] [j] cards j 1 minj = j minj j cards[i], cards[minj] = cards[minj], cards[i] cards[i] cards i cards[minj] cards minj cards[minj] cards minj cards[i] cards i return cards cards cards cards n n n = int(input()) n int(input()) int input() input cards = input().split() cards input().split() ().split () input split copy = list(cards) copy list(cards) list cards print(*BubbleSort(cards, n)) print *BubbleSort(cards, n) BubbleSort(cards, n) BubbleSort cards n print("Stable") print "Stable" print(*SelectionSort(copy, n)) print *SelectionSort(copy, n) SelectionSort(copy, n) SelectionSort copy n print("Stable" if cards == copy else "Not stable") print "Stable" if cards == copy else "Not stable" cards == copy cards copy "Stable" "Not stable" n = int(input()) int(input()) n copy = list(cards) list(cards) copy def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards BubbleSort cards = input().split() input().split() cards def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards SelectionSort
#coding:utf-8
#1_2_C

def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards

def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards

n = int(input())
cards = input().split()
copy = list(cards)

print(*BubbleSort(cards, n))
print("Stable")
print(*SelectionSort(copy, n))
print("Stable" if cards == copy else "Not stable")