def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b

def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s

def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable"


qnt = int(input())
num_list = input().split()

bs = bubble_sort(num_list)
ss = selection_sort(num_list)
print(" ".join(bs))
print(isStable(num_list,bs))
print(" ".join(ss))
print(isStable(num_list,ss)) def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b bubble_sort list_b = num_list[:] list_b num_list[:] num_list : for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
     i range(len(list_b)-1) range len(list_b)-1 len(list_b) len list_b 1 for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
     j range(len(list_b)-1,i,-1) range len(list_b)-1 len(list_b) len list_b 1 i -1 if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
     list_b[j][1] < list_b[j-1][1] list_b[j][1] [j] list_b j 1 list_b[j-1][1] [j-1] list_b j-1 j 1 1 list_b[j],list_b[j-1] = list_b[j-1],list_b[j] list_b[j] list_b j list_b[j-1] list_b j-1 j 1 list_b[j-1] list_b j-1 j 1 list_b[j] list_b j return list_b list_b num_list num_list def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s selection_sort list_s = num_list[:] list_s num_list[:] num_list : for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
     i range(len(list_s)) range len(list_s) len list_s minj = i minj i for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
         j range(i,len(list_s)) range i len(list_s) len list_s if list_s[minj][1] > list_s[j][1]:
                minj = j
         list_s[minj][1] > list_s[j][1] list_s[minj][1] [minj] list_s minj 1 list_s[j][1] [j] list_s j 1 minj = j minj j list_s[i],list_s[minj] = list_s[minj],list_s[i] list_s[i] list_s i list_s[minj] list_s minj list_s[minj] list_s minj list_s[i] list_s i return list_s list_s num_list num_list def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable" isStable leng = int(len(list_x)) leng int(len(list_x)) int len(list_x) len list_x for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
     i range(leng-1) range leng-1 leng 1 for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
     j range(i+1, leng) range i+1 i 1 leng for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
     x range(leng-1) range leng-1 leng 1 for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
     y range(x+1, leng) range x+1 x 1 leng if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
     list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x] list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] list_x[i][1]==list_x[j][1] list_x[i][1] [i] list_x i 1 list_x[j][1] [j] list_x j 1 list_x[i]==list_y[y] list_x[i] list_x i list_y[y] list_y y list_x[j] == list_y[x] list_x[j] list_x j list_y[x] list_y x return "Not stable" "Not stable" return "Stable" "Stable" list_x list_x list_y list_y qnt = int(input()) qnt int(input()) int input() input num_list = input().split() num_list input().split() ().split () input split bs = bubble_sort(num_list) bs bubble_sort(num_list) bubble_sort num_list ss = selection_sort(num_list) ss selection_sort(num_list) selection_sort num_list print(" ".join(bs)) print " ".join(bs) " ".join " " join bs print(isStable(num_list,bs)) print isStable(num_list,bs) isStable num_list bs print(" ".join(ss)) print " ".join(ss) " ".join " " join ss print(isStable(num_list,ss)) print isStable(num_list,ss) isStable num_list ss def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b bubble_sort qnt = int(input()) int(input()) qnt def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s selection_sort def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable" def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable" isStable num_list = input().split() input().split() num_list ss = selection_sort(num_list) selection_sort(num_list) ss bs = bubble_sort(num_list) bubble_sort(num_list) bs
def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b

def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s

def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable"


qnt = int(input())
num_list = input().split()

bs = bubble_sort(num_list)
ss = selection_sort(num_list)
print(" ".join(bs))
print(isStable(num_list,bs))
print(" ".join(ss))
print(isStable(num_list,ss))