def selectionSort(a,b):
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output
    
    
def bubblesort(a,b):
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output


n = int(input())
card = input().split()
number = []
mark = []
number2 = []
mark2 = []
for i in range(n):
    number.append(int(list(card[i])[1]))
    mark.append(list(card[i])[0])
    number2.append(int(list(card[i])[1]))
    mark2.append(list(card[i])[0])

output1 = bubblesort(number,mark)
print("Stable")
output2 = selectionSort(number2, mark2)
print("Stable" if output1 == output2 else "Not stable"  ) def selectionSort(a,b):
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output
    
     selectionSort for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
     i range(len(a)) range len(a) len a mini = i mini i for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
         j range(i,len(a)) range i len(a) len a if a[j] < a[mini]:
                mini = j
         a[j] < a[mini] a[j] a j a[mini] a mini mini = j mini j if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
     i != mini i mini ret = a[i] ret a[i] a i a[i] = a[mini] a[i] a i a[mini] a mini a[mini] = ret a[mini] a mini ret ret = b[i] ret b[i] b i b[i] =b[mini] b[i] b i b[mini] b mini b[mini] = ret b[mini] b mini ret output = [] output [] for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
     i range(len(a)) range len(a) len a output.append(str(b[i])+str(a[i])) output.append output append str(b[i])+str(a[i]) str(b[i]) str b[i] b i str(a[i]) str a[i] a i print(" ".join(output)) print " ".join(output) " ".join " " join output return output output a a b b def bubblesort(a,b):
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output bubblesort swap = True swap True while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
     swap swap = False swap False for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
     j range(1,len(a))[::-1] (1,len(a)) range 1 len(a) len a ::-1 -1 if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
     a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 ret = a[j] ret a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = ret a[j-1] a j-1 j 1 ret ret = b[j] ret b[j] b j b[j] = b[j-1] b[j] b j b[j-1] b j-1 j 1 b[j-1] = ret b[j-1] b j-1 j 1 ret swap = True swap True output = [] output [] for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
     i range(len(a)) range len(a) len a output.append(str(b[i])+str(a[i])) output.append output append str(b[i])+str(a[i]) str(b[i]) str b[i] b i str(a[i]) str a[i] a i print(" ".join(output)) print " ".join(output) " ".join " " join output return output output a a b b n = int(input()) n int(input()) int input() input card = input().split() card input().split() ().split () input split number = [] number [] mark = [] mark [] number2 = [] number2 [] mark2 = [] mark2 [] for i in range(n):
    number.append(int(list(card[i])[1]))
    mark.append(list(card[i])[0])
    number2.append(int(list(card[i])[1]))
    mark2.append(list(card[i])[0]) i range(n) range n number.append(int(list(card[i])[1])) number.append number append int(list(card[i])[1]) int list(card[i])[1] (card[i]) list card[i] card i 1 mark.append(list(card[i])[0]) mark.append mark append list(card[i])[0] (card[i]) list card[i] card i 0 number2.append(int(list(card[i])[1])) number2.append number2 append int(list(card[i])[1]) int list(card[i])[1] (card[i]) list card[i] card i 1 mark2.append(list(card[i])[0]) mark2.append mark2 append list(card[i])[0] (card[i]) list card[i] card i 0 output1 = bubblesort(number,mark) output1 bubblesort(number,mark) bubblesort number mark print("Stable") print "Stable" output2 = selectionSort(number2, mark2) output2 selectionSort(number2, mark2) selectionSort number2 mark2 print("Stable" if output1 == output2 else "Not stable"  ) print "Stable" if output1 == output2 else "Not stable" output1 == output2 output1 output2 "Stable" "Not stable" number2 = [] [] number2 output2 = selectionSort(number2, mark2) selectionSort(number2, mark2) output2 n = int(input()) int(input()) n mark = [] [] mark card = input().split() input().split() card def selectionSort(a,b):
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output
    
     def selectionSort(a,b):
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output
    
     selectionSort number = [] [] number mark2 = [] [] mark2 def bubblesort(a,b):
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output def bubblesort(a,b):
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output bubblesort output1 = bubblesort(number,mark) bubblesort(number,mark) output1
def selectionSort(a,b):
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output
    
    
def bubblesort(a,b):
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output


n = int(input())
card = input().split()
number = []
mark = []
number2 = []
mark2 = []
for i in range(n):
    number.append(int(list(card[i])[1]))
    mark.append(list(card[i])[0])
    number2.append(int(list(card[i])[1]))
    mark2.append(list(card[i])[0])

output1 = bubblesort(number,mark)
print("Stable")
output2 = selectionSort(number2, mark2)
print("Stable" if output1 == output2 else "Not stable"  )