import copy


class Card :
        def __init__(self, char, num) :
                self.text = char
                self.value = num


def bubble_sort(Card, n) :
    for i in range(n) :
        for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j]


def selection_sort(Card, n) :
    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
        Card[i], Card[minj] = Card[minj], Card[i]


def is_stable(lst_bubble, lst_sel) :
    for i in range(len(lst_bubble)) :
        if lst_bubble[i].text != lst_sel[i].text :
            return False
    return True


def print_result(lst, n) :
    for i in range(n-1) :
        print(lst[i].text + str(lst[i].value), end = "")
        print(" ", end = "")
    print(lst[-1].text + str(lst[-1].value))


def main() :
    n = int(input())
    lst1 = input().split()
    card_list1 = []
    for i in range(n) :
        card = Card(lst1[i][0], int(lst1[i][1]))
        card_list1.append(card)

    card_list2 = copy.deepcopy(card_list1)

    bubble_sort(card_list1, n)
    selection_sort(card_list2, n)

    print_result(card_list1, n)
    print("Stable")
    print_result(card_list2, n)
    if (is_stable(card_list1, card_list2)) :
        print("Stable")
    else :
        print("Not stable")


if __name__ == '__main__' :
        main() import copy copy class Card :
        def __init__(self, char, num) :
                self.text = char
                self.value = num Card def __init__(self, char, num) :
                self.text = char
                self.value = num __init__ self.text = char self.text self text char self.value = num self.value self value num self self char char num num def bubble_sort(Card, n) :
    for i in range(n) :
        for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j] bubble_sort for i in range(n) :
        for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j] i range(n) range n for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j] j reversed(range(i+1, n)) reversed range(i+1, n) range i+1 i 1 n if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j] Card[j].value < Card[j-1].value Card[j].value [j] Card j value Card[j-1].value [j-1] Card j-1 j 1 value Card[j], Card[j-1] = Card[j-1], Card[j] Card[j] Card j Card[j-1] Card j-1 j 1 Card[j-1] Card j-1 j 1 Card[j] Card j Card Card n n def selection_sort(Card, n) :
    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
        Card[i], Card[minj] = Card[minj], Card[i] selection_sort for i in range(n) :
        minj = i
        for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
        Card[i], Card[minj] = Card[minj], Card[i] i range(n) range n minj = i minj i for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
         j range(i, n) range i n if Card[j].value < Card[minj].value :
                minj = j
         Card[j].value < Card[minj].value Card[j].value [j] Card j value Card[minj].value [minj] Card minj value minj = j minj j Card[i], Card[minj] = Card[minj], Card[i] Card[i] Card i Card[minj] Card minj Card[minj] Card minj Card[i] Card i Card Card n n def is_stable(lst_bubble, lst_sel) :
    for i in range(len(lst_bubble)) :
        if lst_bubble[i].text != lst_sel[i].text :
            return False
    return True is_stable for i in range(len(lst_bubble)) :
        if lst_bubble[i].text != lst_sel[i].text :
            return False
     i range(len(lst_bubble)) range len(lst_bubble) len lst_bubble if lst_bubble[i].text != lst_sel[i].text :
            return False
     lst_bubble[i].text != lst_sel[i].text lst_bubble[i].text [i] lst_bubble i text lst_sel[i].text [i] lst_sel i text return False False return True True lst_bubble lst_bubble lst_sel lst_sel def print_result(lst, n) :
    for i in range(n-1) :
        print(lst[i].text + str(lst[i].value), end = "")
        print(" ", end = "")
    print(lst[-1].text + str(lst[-1].value)) print_result for i in range(n-1) :
        print(lst[i].text + str(lst[i].value), end = "")
        print(" ", end = "")
     i range(n-1) range n-1 n 1 print(lst[i].text + str(lst[i].value), end = "") print lst[i].text + str(lst[i].value) lst[i].text [i] lst i text str(lst[i].value) str lst[i].value [i] lst i value end = "" end "" print(" ", end = "") print " " end = "" end "" print(lst[-1].text + str(lst[-1].value)) print lst[-1].text + str(lst[-1].value) lst[-1].text [-1] lst -1 text str(lst[-1].value) str lst[-1].value [-1] lst -1 value lst lst n n def main() :
    n = int(input())
    lst1 = input().split()
    card_list1 = []
    for i in range(n) :
        card = Card(lst1[i][0], int(lst1[i][1]))
        card_list1.append(card)

    card_list2 = copy.deepcopy(card_list1)

    bubble_sort(card_list1, n)
    selection_sort(card_list2, n)

    print_result(card_list1, n)
    print("Stable")
    print_result(card_list2, n)
    if (is_stable(card_list1, card_list2)) :
        print("Stable")
    else :
        print("Not stable") main n = int(input()) n int(input()) int input() input lst1 = input().split() lst1 input().split() ().split () input split card_list1 = [] card_list1 [] for i in range(n) :
        card = Card(lst1[i][0], int(lst1[i][1]))
        card_list1.append(card)

     i range(n) range n card = Card(lst1[i][0], int(lst1[i][1])) card Card(lst1[i][0], int(lst1[i][1])) Card lst1[i][0] [i] lst1 i 0 int(lst1[i][1]) int lst1[i][1] [i] lst1 i 1 card_list1.append(card) card_list1.append card_list1 append card card_list2 = copy.deepcopy(card_list1) card_list2 copy.deepcopy(card_list1) copy.deepcopy copy deepcopy card_list1 bubble_sort(card_list1, n) bubble_sort card_list1 n selection_sort(card_list2, n) selection_sort card_list2 n print_result(card_list1, n) print_result card_list1 n print("Stable") print "Stable" print_result(card_list2, n) print_result card_list2 n if (is_stable(card_list1, card_list2)) :
        print("Stable")
    else :
        print("Not stable") is_stable(card_list1, card_list2) is_stable card_list1 card_list2 print("Stable") print "Stable" print("Not stable") print "Not stable" if __name__ == '__main__' :
        main() __name__ == '__main__' __name__ '__main__' main() main def is_stable(lst_bubble, lst_sel) :
    for i in range(len(lst_bubble)) :
        if lst_bubble[i].text != lst_sel[i].text :
            return False
    return True def is_stable(lst_bubble, lst_sel) :
    for i in range(len(lst_bubble)) :
        if lst_bubble[i].text != lst_sel[i].text :
            return False
    return True is_stable class Card :
        def __init__(self, char, num) :
                self.text = char
                self.value = num class Card :
        def __init__(self, char, num) :
                self.text = char
                self.value = num Card def main() :
    n = int(input())
    lst1 = input().split()
    card_list1 = []
    for i in range(n) :
        card = Card(lst1[i][0], int(lst1[i][1]))
        card_list1.append(card)

    card_list2 = copy.deepcopy(card_list1)

    bubble_sort(card_list1, n)
    selection_sort(card_list2, n)

    print_result(card_list1, n)
    print("Stable")
    print_result(card_list2, n)
    if (is_stable(card_list1, card_list2)) :
        print("Stable")
    else :
        print("Not stable") def main() :
    n = int(input())
    lst1 = input().split()
    card_list1 = []
    for i in range(n) :
        card = Card(lst1[i][0], int(lst1[i][1]))
        card_list1.append(card)

    card_list2 = copy.deepcopy(card_list1)

    bubble_sort(card_list1, n)
    selection_sort(card_list2, n)

    print_result(card_list1, n)
    print("Stable")
    print_result(card_list2, n)
    if (is_stable(card_list1, card_list2)) :
        print("Stable")
    else :
        print("Not stable") main def bubble_sort(Card, n) :
    for i in range(n) :
        for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j] def bubble_sort(Card, n) :
    for i in range(n) :
        for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j] bubble_sort def print_result(lst, n) :
    for i in range(n-1) :
        print(lst[i].text + str(lst[i].value), end = "")
        print(" ", end = "")
    print(lst[-1].text + str(lst[-1].value)) def print_result(lst, n) :
    for i in range(n-1) :
        print(lst[i].text + str(lst[i].value), end = "")
        print(" ", end = "")
    print(lst[-1].text + str(lst[-1].value)) print_result def selection_sort(Card, n) :
    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
        Card[i], Card[minj] = Card[minj], Card[i] def selection_sort(Card, n) :
    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
        Card[i], Card[minj] = Card[minj], Card[i] selection_sort
import copy


class Card :
        def __init__(self, char, num) :
                self.text = char
                self.value = num


def bubble_sort(Card, n) :
    for i in range(n) :
        for j in reversed(range(i+1, n)) :
            if Card[j].value < Card[j-1].value :
                Card[j], Card[j-1] = Card[j-1], Card[j]


def selection_sort(Card, n) :
    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if Card[j].value < Card[minj].value :
                minj = j
        Card[i], Card[minj] = Card[minj], Card[i]


def is_stable(lst_bubble, lst_sel) :
    for i in range(len(lst_bubble)) :
        if lst_bubble[i].text != lst_sel[i].text :
            return False
    return True


def print_result(lst, n) :
    for i in range(n-1) :
        print(lst[i].text + str(lst[i].value), end = "")
        print(" ", end = "")
    print(lst[-1].text + str(lst[-1].value))


def main() :
    n = int(input())
    lst1 = input().split()
    card_list1 = []
    for i in range(n) :
        card = Card(lst1[i][0], int(lst1[i][1]))
        card_list1.append(card)

    card_list2 = copy.deepcopy(card_list1)

    bubble_sort(card_list1, n)
    selection_sort(card_list2, n)

    print_result(card_list1, n)
    print("Stable")
    print_result(card_list2, n)
    if (is_stable(card_list1, card_list2)) :
        print("Stable")
    else :
        print("Not stable")


if __name__ == '__main__' :
        main()