n, card = int(input()), input().split()
card1, card2 = card[:], card[:]

for i in range(n-1):
    for j in range(n-1, i, -1):
        if int(card1[j][1]) < int(card1[j-1][1]):
            card1[j], card1[j-1] = card1[j-1], card1[j]
print(" ".join(card1))
print("Stable")

for i in range(n-1):
    for j in range(i+1, n):
        if j == i+1:
            idx = j
        elif int(card2[idx][1]) > int(card2[j][1]):
            idx = j
    if int(card2[i][1]) > int(card2[idx][1]):
        card2[i], card2[idx] = card2[idx], card2[i]
print(" ".join(card2))
if card1 == card2:
    print("Stable")
else:
    print("Not stable")
 n, card = int(input()), input().split() n int(input()) int input() input card input().split() ().split () input split card1, card2 = card[:], card[:] card1 card[:] card : card2 card[:] card : for i in range(n-1):
    for j in range(n-1, i, -1):
        if int(card1[j][1]) < int(card1[j-1][1]):
            card1[j], card1[j-1] = card1[j-1], card1[j] i range(n-1) range n-1 n 1 for j in range(n-1, i, -1):
        if int(card1[j][1]) < int(card1[j-1][1]):
            card1[j], card1[j-1] = card1[j-1], card1[j] j range(n-1, i, -1) range n-1 n 1 i -1 if int(card1[j][1]) < int(card1[j-1][1]):
            card1[j], card1[j-1] = card1[j-1], card1[j] int(card1[j][1]) < int(card1[j-1][1]) int(card1[j][1]) int card1[j][1] [j] card1 j 1 int(card1[j-1][1]) int card1[j-1][1] [j-1] card1 j-1 j 1 1 card1[j], card1[j-1] = card1[j-1], card1[j] card1[j] card1 j card1[j-1] card1 j-1 j 1 card1[j-1] card1 j-1 j 1 card1[j] card1 j print(" ".join(card1)) print " ".join(card1) " ".join " " join card1 print("Stable") print "Stable" for i in range(n-1):
    for j in range(i+1, n):
        if j == i+1:
            idx = j
        elif int(card2[idx][1]) > int(card2[j][1]):
            idx = j
    if int(card2[i][1]) > int(card2[idx][1]):
        card2[i], card2[idx] = card2[idx], card2[i] i range(n-1) range n-1 n 1 for j in range(i+1, n):
        if j == i+1:
            idx = j
        elif int(card2[idx][1]) > int(card2[j][1]):
            idx = j
     j range(i+1, n) range i+1 i 1 n if j == i+1:
            idx = j
        elif int(card2[idx][1]) > int(card2[j][1]):
            idx = j
     j == i+1 j i+1 i 1 idx = j idx j elif int(card2[idx][1]) > int(card2[j][1]):
            idx = j
     int(card2[idx][1]) > int(card2[j][1]) int(card2[idx][1]) int card2[idx][1] [idx] card2 idx 1 int(card2[j][1]) int card2[j][1] [j] card2 j 1 idx = j idx j if int(card2[i][1]) > int(card2[idx][1]):
        card2[i], card2[idx] = card2[idx], card2[i] int(card2[i][1]) > int(card2[idx][1]) int(card2[i][1]) int card2[i][1] [i] card2 i 1 int(card2[idx][1]) int card2[idx][1] [idx] card2 idx 1 card2[i], card2[idx] = card2[idx], card2[i] card2[i] card2 i card2[idx] card2 idx card2[idx] card2 idx card2[i] card2 i print(" ".join(card2)) print " ".join(card2) " ".join " " join card2 if card1 == card2:
    print("Stable")
else:
    print("Not stable") card1 == card2 card1 card2 print("Stable") print "Stable" print("Not stable") print "Not stable" card2 = card[:], card[:] card[:] card2 idx = j j idx n, card = int(input()), input().split() int(input()) n card = int(input()), input().split() input().split() card card1, card2 = card[:], card[:] card[:] card1 idx = j j idx
n, card = int(input()), input().split()
card1, card2 = card[:], card[:]

for i in range(n-1):
    for j in range(n-1, i, -1):
        if int(card1[j][1]) < int(card1[j-1][1]):
            card1[j], card1[j-1] = card1[j-1], card1[j]
print(" ".join(card1))
print("Stable")

for i in range(n-1):
    for j in range(i+1, n):
        if j == i+1:
            idx = j
        elif int(card2[idx][1]) > int(card2[j][1]):
            idx = j
    if int(card2[i][1]) > int(card2[idx][1]):
        card2[i], card2[idx] = card2[idx], card2[i]
print(" ".join(card2))
if card1 == card2:
    print("Stable")
else:
    print("Not stable")

