from copy import copy

n = int(input())
cards = [(s[0],int(s[1])) for s in input().split()]

cards_1 = copy(cards)
cards_2 = copy(cards)

need_to_sort = True
while need_to_sort:
    need_to_sort = False
    for index in range(len(cards_1) - 1, 0, -1):
        if cards_1[index][1] < cards_1[index-1][1]:
            cards_1[index], cards_1[index-1] = cards_1[index-1], cards_1[index]
            need_to_sort = True

print(" ".join([s[0]+ str(s[1]) for s in cards_1]))
print("Stable")

for idx1 in range(len(cards_2)):
    mins = idx1
    for idx2 in range(idx1, len(cards_2)):
        if cards_2[idx2][1] < cards_2[mins][1]:
            mins = idx2
    
    if mins != idx1:
        cards_2[idx1], cards_2[mins] = cards_2[mins], cards_2[idx1]

print(" ".join([s[0]+ str(s[1]) for s in cards_2]))

is_stable = True
for index in range(n):
    if cards_1[index] != cards_2[index]:
        is_stable = False
        break

print("Stable" if is_stable else "Not stable") from copy import copy n = int(input()) n int(input()) int input() input (s[0],int(s[1])) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() (s[0],int(s[1])) s[0] s 0 int(s[1]) int s[1] s 1 cards = [(s[0],int(s[1])) for s in input().split()] cards [(s[0],int(s[1])) for s in input().split()] cards_1 = copy(cards) cards_1 copy(cards) copy cards cards_2 = copy(cards) cards_2 copy(cards) copy cards need_to_sort = True need_to_sort True while need_to_sort:
    need_to_sort = False
    for index in range(len(cards_1) - 1, 0, -1):
        if cards_1[index][1] < cards_1[index-1][1]:
            cards_1[index], cards_1[index-1] = cards_1[index-1], cards_1[index]
            need_to_sort = True need_to_sort need_to_sort = False need_to_sort False for index in range(len(cards_1) - 1, 0, -1):
        if cards_1[index][1] < cards_1[index-1][1]:
            cards_1[index], cards_1[index-1] = cards_1[index-1], cards_1[index]
            need_to_sort = True index range(len(cards_1) - 1, 0, -1) range len(cards_1) - 1 len(cards_1) len cards_1 1 0 -1 if cards_1[index][1] < cards_1[index-1][1]:
            cards_1[index], cards_1[index-1] = cards_1[index-1], cards_1[index]
            need_to_sort = True cards_1[index][1] < cards_1[index-1][1] cards_1[index][1] [index] cards_1 index 1 cards_1[index-1][1] [index-1] cards_1 index-1 index 1 1 cards_1[index], cards_1[index-1] = cards_1[index-1], cards_1[index] cards_1[index] cards_1 index cards_1[index-1] cards_1 index-1 index 1 cards_1[index-1] cards_1 index-1 index 1 cards_1[index] cards_1 index need_to_sort = True need_to_sort True s[0]+ str(s[1]) for s in cards_1 for s in cards_1 s cards_1 for s in cards_1 s[0]+ str(s[1]) s[0] s 0 str(s[1]) str s[1] s 1 print(" ".join([s[0]+ str(s[1]) for s in cards_1])) print " ".join([s[0]+ str(s[1]) for s in cards_1]) " ".join " " join [s[0]+ str(s[1]) for s in cards_1] print("Stable") print "Stable" for idx1 in range(len(cards_2)):
    mins = idx1
    for idx2 in range(idx1, len(cards_2)):
        if cards_2[idx2][1] < cards_2[mins][1]:
            mins = idx2
    
    if mins != idx1:
        cards_2[idx1], cards_2[mins] = cards_2[mins], cards_2[idx1] idx1 range(len(cards_2)) range len(cards_2) len cards_2 mins = idx1 mins idx1 for idx2 in range(idx1, len(cards_2)):
        if cards_2[idx2][1] < cards_2[mins][1]:
            mins = idx2
    
     idx2 range(idx1, len(cards_2)) range idx1 len(cards_2) len cards_2 if cards_2[idx2][1] < cards_2[mins][1]:
            mins = idx2
    
     cards_2[idx2][1] < cards_2[mins][1] cards_2[idx2][1] [idx2] cards_2 idx2 1 cards_2[mins][1] [mins] cards_2 mins 1 mins = idx2 mins idx2 if mins != idx1:
        cards_2[idx1], cards_2[mins] = cards_2[mins], cards_2[idx1] mins != idx1 mins idx1 cards_2[idx1], cards_2[mins] = cards_2[mins], cards_2[idx1] cards_2[idx1] cards_2 idx1 cards_2[mins] cards_2 mins cards_2[mins] cards_2 mins cards_2[idx1] cards_2 idx1 s[0]+ str(s[1]) for s in cards_2 for s in cards_2 s cards_2 for s in cards_2 s[0]+ str(s[1]) s[0] s 0 str(s[1]) str s[1] s 1 print(" ".join([s[0]+ str(s[1]) for s in cards_2])) print " ".join([s[0]+ str(s[1]) for s in cards_2]) " ".join " " join [s[0]+ str(s[1]) for s in cards_2] is_stable = True is_stable True for index in range(n):
    if cards_1[index] != cards_2[index]:
        is_stable = False
        break index range(n) range n if cards_1[index] != cards_2[index]:
        is_stable = False
        break cards_1[index] != cards_2[index] cards_1[index] cards_1 index cards_2[index] cards_2 index is_stable = False is_stable False break print("Stable" if is_stable else "Not stable") print "Stable" if is_stable else "Not stable" is_stable "Stable" "Not stable" is_stable = True True is_stable is_stable = False False is_stable mins = idx1 idx1 mins cards_1 = copy(cards) copy(cards) cards_1 cards_2 = copy(cards) copy(cards) cards_2 need_to_sort = True True need_to_sort need_to_sort = False False need_to_sort n = int(input()) int(input()) n need_to_sort = True True need_to_sort cards = [(s[0],int(s[1])) for s in input().split()] [(s[0],int(s[1])) for s in input().split()] cards mins = idx2 idx2 mins
from copy import copy

n = int(input())
cards = [(s[0],int(s[1])) for s in input().split()]

cards_1 = copy(cards)
cards_2 = copy(cards)

need_to_sort = True
while need_to_sort:
    need_to_sort = False
    for index in range(len(cards_1) - 1, 0, -1):
        if cards_1[index][1] < cards_1[index-1][1]:
            cards_1[index], cards_1[index-1] = cards_1[index-1], cards_1[index]
            need_to_sort = True

print(" ".join([s[0]+ str(s[1]) for s in cards_1]))
print("Stable")

for idx1 in range(len(cards_2)):
    mins = idx1
    for idx2 in range(idx1, len(cards_2)):
        if cards_2[idx2][1] < cards_2[mins][1]:
            mins = idx2
    
    if mins != idx1:
        cards_2[idx1], cards_2[mins] = cards_2[mins], cards_2[idx1]

print(" ".join([s[0]+ str(s[1]) for s in cards_2]))

is_stable = True
for index in range(n):
    if cards_1[index] != cards_2[index]:
        is_stable = False
        break

print("Stable" if is_stable else "Not stable")
