class Card:
    def __init__(self, inf):
        self.num = int(inf[1])
        self.inf = inf

n, card = int(input()), [Card(i) for i in input().split()]
card1 = card[:]

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

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

n, card = int(input()), [Card(i) for i in input().split()]
card1 = card[:]

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

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

