def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True

def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
    
def BubbleSort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j]

def SelectionSort(c, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    
num = int(input())
data = input().split(' ')

copy_data = data.copy()
BubbleSort(copy_data, num)
print(' '.join(copy_data))
if isStable(copy_data, copy_data):
    print("Stable")
else:
    print("Not stable")

bubble_sort_data = data.copy()
SelectionSort(bubble_sort_data, num)
print(' '.join(bubble_sort_data))
if isStable(bubble_sort_data, copy_data):
    print("Stable")
else:
    print("Not stable") def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True isStable num = len(before_sort) num len(before_sort) len before_sort for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
     i range(0, num-1) range 0 num-1 num 1 for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
     j range(i+1, num) range i+1 i 1 num for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
     a range(0, num-1) range 0 num-1 num 1 for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
     b range(a+1, num) range a+1 a 1 num if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
     before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a] before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] before_sort[i][1] == after_sort[j][1] before_sort[i][1] [i] before_sort i 1 after_sort[j][1] [j] after_sort j 1 before_sort[i] == after_sort[b] before_sort[i] before_sort i after_sort[b] after_sort b before_sort[j] == after_sort[a] before_sort[j] before_sort j after_sort[a] after_sort a return False False return True True before_sort before_sort after_sort after_sort def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
     isStable2 for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
     i range(0, len(sorted_data)) range 0 len(sorted_data) len sorted_data if sorted_data[i] != bubble_sort_data[i]:
            return False
     sorted_data[i] != bubble_sort_data[i] sorted_data[i] sorted_data i bubble_sort_data[i] bubble_sort_data i return False False return True True sorted_data sorted_data bubble_sort_data bubble_sort_data def BubbleSort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j] BubbleSort for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j] i range(0, n) range 0 n for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j] j range(n-1, i, -1) range n-1 n 1 i -1 if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j] int(c[j][1]) < int(c[j-1][1]) int(c[j][1]) int c[j][1] [j] c j 1 int(c[j-1][1]) int c[j-1][1] [j-1] c j-1 j 1 1 c[j], c[j-1] = c[j-1], c[j] c[j] c j c[j-1] c j-1 j 1 c[j-1] c j-1 j 1 c[j] c j c c n n def SelectionSort(c, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
     SelectionSort for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
     i range(0, n) range 0 n minj = i minj i for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
         j range(i, n) range i n if int(c[j][1]) < int(c[minj][1]):
                minj = j
         int(c[j][1]) < int(c[minj][1]) int(c[j][1]) int c[j][1] [j] c j 1 int(c[minj][1]) int c[minj][1] [minj] c minj 1 minj = j minj j c[i], c[minj] = c[minj], c[i] c[i] c i c[minj] c minj c[minj] c minj c[i] c i c c n n num = int(input()) num int(input()) int input() input data = input().split(' ') data input().split(' ') ().split () input split ' ' copy_data = data.copy() copy_data data.copy() data.copy data copy BubbleSort(copy_data, num) BubbleSort copy_data num print(' '.join(copy_data)) print ' '.join(copy_data) ' '.join ' ' join copy_data if isStable(copy_data, copy_data):
    print("Stable")
else:
    print("Not stable") isStable(copy_data, copy_data) isStable copy_data copy_data print("Stable") print "Stable" print("Not stable") print "Not stable" bubble_sort_data = data.copy() bubble_sort_data data.copy() data.copy data copy SelectionSort(bubble_sort_data, num) SelectionSort bubble_sort_data num print(' '.join(bubble_sort_data)) print ' '.join(bubble_sort_data) ' '.join ' ' join bubble_sort_data if isStable(bubble_sort_data, copy_data):
    print("Stable")
else:
    print("Not stable") isStable(bubble_sort_data, copy_data) isStable bubble_sort_data copy_data print("Stable") print "Stable" print("Not stable") print "Not stable" def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True isStable copy_data = data.copy() data.copy() copy_data num = int(input()) int(input()) num def BubbleSort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j] def BubbleSort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j] BubbleSort def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
     def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
     isStable2 def SelectionSort(c, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
     def SelectionSort(c, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
     SelectionSort data = input().split(' ') input().split(' ') data bubble_sort_data = data.copy() data.copy() bubble_sort_data
def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True

def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
    
def BubbleSort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j]

def SelectionSort(c, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    
num = int(input())
data = input().split(' ')

copy_data = data.copy()
BubbleSort(copy_data, num)
print(' '.join(copy_data))
if isStable(copy_data, copy_data):
    print("Stable")
else:
    print("Not stable")

bubble_sort_data = data.copy()
SelectionSort(bubble_sort_data, num)
print(' '.join(bubble_sort_data))
if isStable(bubble_sort_data, copy_data):
    print("Stable")
else:
    print("Not stable")