def bubble_sort(seq):
    for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
    return seq


def selection_sort(seq):
    for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
    return seq



n = int(input())
*seq,= input().split()
seq2 = seq[:]

bl = bubble_sort(seq)
print(*bl)
print("Stable")
sl = selection_sort(seq2)
print(*sl)
if bl == sl:print("Stable")
else:print("Not stable")
 def bubble_sort(seq):
    for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
    return seq bubble_sort for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
     i range(len(seq)) range len(seq) len seq flag = 0 flag 0 for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
         j range(len(seq)-1,i,-1) range len(seq)-1 len(seq) len seq 1 i -1 if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
         seq[j-1][1] > seq[j][1] seq[j-1][1] [j-1] seq j-1 j 1 1 seq[j][1] [j] seq j 1 seq[j-1],seq[j] = seq[j],seq[j-1] seq[j-1] seq j-1 j 1 seq[j] seq j seq[j] seq j seq[j-1] seq j-1 j 1 flag = 1 flag 1 if flag == 0: break
     flag == 0 flag 0 return seq seq seq seq def selection_sort(seq):
    for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
    return seq selection_sort for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
     i range(len(seq)) range len(seq) len seq mini = i mini i for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
         j range(i,len(seq)) range i len(seq) len seq if seq[mini][1] > seq[j][1]:mini = j
         seq[mini][1] > seq[j][1] seq[mini][1] [mini] seq mini 1 seq[j][1] [j] seq j 1 seq[i],seq[mini] = seq[mini],seq[i] seq[i] seq i seq[mini] seq mini seq[mini] seq mini seq[i] seq i return seq seq seq seq n = int(input()) n int(input()) int input() input *seq,= input().split() *seq seq input().split() ().split () input split seq2 = seq[:] seq2 seq[:] seq : bl = bubble_sort(seq) bl bubble_sort(seq) bubble_sort seq print(*bl) print *bl bl print("Stable") print "Stable" sl = selection_sort(seq2) sl selection_sort(seq2) selection_sort seq2 print(*sl) print *sl sl if bl == sl:print("Stable")
else:print("Not stable") bl == sl bl sl def bubble_sort(seq):
    for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
    return seq def bubble_sort(seq):
    for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
    return seq bubble_sort def selection_sort(seq):
    for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
    return seq def selection_sort(seq):
    for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
    return seq selection_sort seq2 = seq[:] seq[:] seq2 bl = bubble_sort(seq) bubble_sort(seq) bl sl = selection_sort(seq2) selection_sort(seq2) sl n = int(input()) int(input()) n
def bubble_sort(seq):
    for i in range(len(seq)):
        flag = 0
        for j in range(len(seq)-1,i,-1):
            if seq[j-1][1] > seq[j][1]:
                seq[j-1],seq[j] = seq[j],seq[j-1]
                flag = 1
        if flag == 0: break
    return seq


def selection_sort(seq):
    for i in range(len(seq)):
        mini = i
        for j in range(i,len(seq)):
            if seq[mini][1] > seq[j][1]:mini = j
        seq[i],seq[mini] = seq[mini],seq[i]
    return seq



n = int(input())
*seq,= input().split()
seq2 = seq[:]

bl = bubble_sort(seq)
print(*bl)
print("Stable")
sl = selection_sort(seq2)
print(*sl)
if bl == sl:print("Stable")
else:print("Not stable")

