n = int(input())

cards_b = input().split()
cards_s = list(cards_b)

# BubbleSort
for i in range(n):
    for j in range(n - 1, i, -1):
        if int(cards_b[j][1]) < int(cards_b[j - 1][1]):
            cards_b[j], cards_b[j - 1] = cards_b[j - 1], cards_b[j]

#SelectionSort
for i in range(n):
    min_i = i
    for j in range(i, n):
        if int(cards_s[j][1]) < int(cards_s[min_i][1]):
            min_i = j
    cards_s[i], cards_s[min_i] = cards_s[min_i], cards_s[i]

print(" ".join(cards_b))
print("Stable")
print(" ".join(cards_s))

if cards_b == cards_s:
    print("Stable")
else:
    print("Not stable") n = int(input()) n int(input()) int input() input cards_b = input().split() cards_b input().split() ().split () input split cards_s = list(cards_b) cards_s list(cards_b) list cards_b for i in range(n):
    for j in range(n - 1, i, -1):
        if int(cards_b[j][1]) < int(cards_b[j - 1][1]):
            cards_b[j], cards_b[j - 1] = cards_b[j - 1], cards_b[j]

#SelectionSort i range(n) range n for j in range(n - 1, i, -1):
        if int(cards_b[j][1]) < int(cards_b[j - 1][1]):
            cards_b[j], cards_b[j - 1] = cards_b[j - 1], cards_b[j]

#SelectionSort j range(n - 1, i, -1) range n - 1 n 1 i -1 if int(cards_b[j][1]) < int(cards_b[j - 1][1]):
            cards_b[j], cards_b[j - 1] = cards_b[j - 1], cards_b[j]

#SelectionSort int(cards_b[j][1]) < int(cards_b[j - 1][1]) int(cards_b[j][1]) int cards_b[j][1] [j] cards_b j 1 int(cards_b[j - 1][1]) int cards_b[j - 1][1] [j - 1] cards_b j - 1 j 1 1 cards_b[j], cards_b[j - 1] = cards_b[j - 1], cards_b[j] cards_b[j] cards_b j cards_b[j - 1] cards_b j - 1 j 1 cards_b[j - 1] cards_b j - 1 j 1 cards_b[j] cards_b j for i in range(n):
    min_i = i
    for j in range(i, n):
        if int(cards_s[j][1]) < int(cards_s[min_i][1]):
            min_i = j
    cards_s[i], cards_s[min_i] = cards_s[min_i], cards_s[i] i range(n) range n min_i = i min_i i for j in range(i, n):
        if int(cards_s[j][1]) < int(cards_s[min_i][1]):
            min_i = j
     j range(i, n) range i n if int(cards_s[j][1]) < int(cards_s[min_i][1]):
            min_i = j
     int(cards_s[j][1]) < int(cards_s[min_i][1]) int(cards_s[j][1]) int cards_s[j][1] [j] cards_s j 1 int(cards_s[min_i][1]) int cards_s[min_i][1] [min_i] cards_s min_i 1 min_i = j min_i j cards_s[i], cards_s[min_i] = cards_s[min_i], cards_s[i] cards_s[i] cards_s i cards_s[min_i] cards_s min_i cards_s[min_i] cards_s min_i cards_s[i] cards_s i print(" ".join(cards_b)) print " ".join(cards_b) " ".join " " join cards_b print("Stable") print "Stable" print(" ".join(cards_s)) print " ".join(cards_s) " ".join " " join cards_s if cards_b == cards_s:
    print("Stable")
else:
    print("Not stable") cards_b == cards_s cards_b cards_s print("Stable") print "Stable" print("Not stable") print "Not stable" n = int(input()) int(input()) n min_i = j j min_i min_i = i i min_i cards_b = input().split() input().split() cards_b cards_s = list(cards_b) list(cards_b) cards_s
n = int(input())

cards_b = input().split()
cards_s = list(cards_b)

# BubbleSort
for i in range(n):
    for j in range(n - 1, i, -1):
        if int(cards_b[j][1]) < int(cards_b[j - 1][1]):
            cards_b[j], cards_b[j - 1] = cards_b[j - 1], cards_b[j]

#SelectionSort
for i in range(n):
    min_i = i
    for j in range(i, n):
        if int(cards_s[j][1]) < int(cards_s[min_i][1]):
            min_i = j
    cards_s[i], cards_s[min_i] = cards_s[min_i], cards_s[i]

print(" ".join(cards_b))
print("Stable")
print(" ".join(cards_s))

if cards_b == cards_s:
    print("Stable")
else:
    print("Not stable")