class Card():

    def bubble_sort(self):
        bubble_card = [i for i in self]
        for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
        return bubble_card


    def selection_sort(self):
        select_card = [i for i in self]
        for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
        return select_card


    def stable_sort(self):
        sort_card = [i for i in self]
        sort = []
        for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
        sort = sort_card
        return sort





def main():
    n = int(input())
    cards = [i for i in input().split()]
    bubble = Card.bubble_sort(cards)
    select = Card.selection_sort(cards)
    stable = Card.stable_sort(cards)

    for i in range(len(bubble)):
        print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='')
    print('Stable') if bubble == stable else print('Not stable')

    for i in range(len(select)):
        print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='')
    print('Stable') if select == stable else print('Not stable')


if __name__ == '__main__':
    main() class Card():

    def bubble_sort(self):
        bubble_card = [i for i in self]
        for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
        return bubble_card


    def selection_sort(self):
        select_card = [i for i in self]
        for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
        return select_card


    def stable_sort(self):
        sort_card = [i for i in self]
        sort = []
        for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
        sort = sort_card
        return sort Card def bubble_sort(self):
        bubble_card = [i for i in self]
        for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
        return bubble_card


     bubble_sort i for i in self for i in self i self for i in self i bubble_card = [i for i in self] bubble_card [i for i in self] for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
         i range(len(bubble_card)) range len(bubble_card) len bubble_card for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
         j range(len(self)-1, i, -1) range len(self)-1 len(self) len self 1 i -1 if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
         bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD') bubble_card[j].strip('SHCD') [j].strip [j] bubble_card j strip 'SHCD' bubble_card[j-1].strip('SHCD') [j-1].strip [j-1] bubble_card j-1 j 1 strip 'SHCD' bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j] bubble_card[j] bubble_card j bubble_card[j-1] bubble_card j-1 j 1 bubble_card[j-1] bubble_card j-1 j 1 bubble_card[j] bubble_card j return bubble_card bubble_card self self def selection_sort(self):
        select_card = [i for i in self]
        for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
        return select_card


     selection_sort i for i in self for i in self i self for i in self i select_card = [i for i in self] select_card [i for i in self] for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
         i range(len(select_card)) range len(select_card) len select_card minj = i minj i change = False change False for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
             j range(i + 1, len(select_card)) range i + 1 i 1 len(select_card) len select_card if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
             select_card[minj].strip('SHCD') > select_card[j].strip('SHCD') select_card[minj].strip('SHCD') [minj].strip [minj] select_card minj strip 'SHCD' select_card[j].strip('SHCD') [j].strip [j] select_card j strip 'SHCD' minj = j minj j change = True change True if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
         change select_card[i], select_card[minj] = select_card[minj], select_card[i] select_card[i] select_card i select_card[minj] select_card minj select_card[minj] select_card minj select_card[i] select_card i return select_card select_card self self def stable_sort(self):
        sort_card = [i for i in self]
        sort = []
        for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
        sort = sort_card
        return sort stable_sort i for i in self for i in self i self for i in self i sort_card = [i for i in self] sort_card [i for i in self] sort = [] sort [] for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
         i range(len(sort_card)-1) range len(sort_card)-1 len(sort_card) len sort_card 1 min = i min i for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
             j range(i+1, len(sort_card)) range i+1 i 1 len(sort_card) len sort_card if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
             int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')) int(sort_card[min].strip('SHCD')) int sort_card[min].strip('SHCD') [min].strip [min] sort_card min strip 'SHCD' int(sort_card[j].strip('SHCD')) int sort_card[j].strip('SHCD') [j].strip [j] sort_card j strip 'SHCD' min = j min j min_card = sort_card[min] min_card sort_card[min] sort_card min sort_card.pop(min) sort_card.pop sort_card pop min sort_card.insert(i,min_card) sort_card.insert sort_card insert i min_card sort = sort_card sort sort_card return sort sort self self def main():
    n = int(input())
    cards = [i for i in input().split()]
    bubble = Card.bubble_sort(cards)
    select = Card.selection_sort(cards)
    stable = Card.stable_sort(cards)

    for i in range(len(bubble)):
        print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='')
    print('Stable') if bubble == stable else print('Not stable')

    for i in range(len(select)):
        print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='')
    print('Stable') if select == stable else print('Not stable') main n = int(input()) n int(input()) int input() input i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i cards = [i for i in input().split()] cards [i for i in input().split()] bubble = Card.bubble_sort(cards) bubble Card.bubble_sort(cards) Card.bubble_sort Card bubble_sort cards select = Card.selection_sort(cards) select Card.selection_sort(cards) Card.selection_sort Card selection_sort cards stable = Card.stable_sort(cards) stable Card.stable_sort(cards) Card.stable_sort Card stable_sort cards for i in range(len(bubble)):
        print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='')
     i range(len(bubble)) range len(bubble) len bubble print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='') i == len(bubble)-1 i len(bubble)-1 len(bubble) len bubble 1 print(bubble[i]) print bubble[i] bubble i print(str(bubble[i])+' ',end='') print str(bubble[i])+' ' str(bubble[i]) str bubble[i] bubble i ' ' end='' end '' print('Stable') if bubble == stable else print('Not stable') bubble == stable bubble stable print('Stable') print 'Stable' print('Not stable') print 'Not stable' for i in range(len(select)):
        print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='')
     i range(len(select)) range len(select) len select print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='') i == len(select)-1 i len(select)-1 len(select) len select 1 print(select[i]) print select[i] select i print(str(select[i])+' ',end='') print str(select[i])+' ' str(select[i]) str select[i] select i ' ' end='' end '' print('Stable') if select == stable else print('Not stable') select == stable select stable print('Stable') print 'Stable' print('Not stable') print 'Not stable' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main class Card():

    def bubble_sort(self):
        bubble_card = [i for i in self]
        for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
        return bubble_card


    def selection_sort(self):
        select_card = [i for i in self]
        for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
        return select_card


    def stable_sort(self):
        sort_card = [i for i in self]
        sort = []
        for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
        sort = sort_card
        return sort class Card():

    def bubble_sort(self):
        bubble_card = [i for i in self]
        for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
        return bubble_card


    def selection_sort(self):
        select_card = [i for i in self]
        for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
        return select_card


    def stable_sort(self):
        sort_card = [i for i in self]
        sort = []
        for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
        sort = sort_card
        return sort Card def main():
    n = int(input())
    cards = [i for i in input().split()]
    bubble = Card.bubble_sort(cards)
    select = Card.selection_sort(cards)
    stable = Card.stable_sort(cards)

    for i in range(len(bubble)):
        print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='')
    print('Stable') if bubble == stable else print('Not stable')

    for i in range(len(select)):
        print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='')
    print('Stable') if select == stable else print('Not stable') def main():
    n = int(input())
    cards = [i for i in input().split()]
    bubble = Card.bubble_sort(cards)
    select = Card.selection_sort(cards)
    stable = Card.stable_sort(cards)

    for i in range(len(bubble)):
        print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='')
    print('Stable') if bubble == stable else print('Not stable')

    for i in range(len(select)):
        print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='')
    print('Stable') if select == stable else print('Not stable') main
class Card():

    def bubble_sort(self):
        bubble_card = [i for i in self]
        for i in range(len(bubble_card)):
            for j in range(len(self)-1, i, -1):
                if bubble_card[j].strip('SHCD') < bubble_card[j-1].strip('SHCD'):
                    bubble_card[j], bubble_card[j-1] = bubble_card[j-1], bubble_card[j]
        return bubble_card


    def selection_sort(self):
        select_card = [i for i in self]
        for i in range(len(select_card)):
            minj = i
            change = False
            for j in range(i + 1, len(select_card)):
                if select_card[minj].strip('SHCD') > select_card[j].strip('SHCD'):
                    minj = j
                    change = True
            if change:
                select_card[i], select_card[minj] = select_card[minj], select_card[i]
        return select_card


    def stable_sort(self):
        sort_card = [i for i in self]
        sort = []
        for i in range(len(sort_card)-1):
            min = i
            for j in range(i+1, len(sort_card)):
                if int(sort_card[min].strip('SHCD')) > int(sort_card[j].strip('SHCD')):
                    min = j
            min_card = sort_card[min]
            sort_card.pop(min)
            sort_card.insert(i,min_card)
        sort = sort_card
        return sort





def main():
    n = int(input())
    cards = [i for i in input().split()]
    bubble = Card.bubble_sort(cards)
    select = Card.selection_sort(cards)
    stable = Card.stable_sort(cards)

    for i in range(len(bubble)):
        print(bubble[i]) if i == len(bubble)-1 else print(str(bubble[i])+' ',end='')
    print('Stable') if bubble == stable else print('Not stable')

    for i in range(len(select)):
        print(select[i]) if i == len(select)-1 else print(str(select[i])+' ',end='')
    print('Stable') if select == stable else print('Not stable')


if __name__ == '__main__':
    main()