#!/usr/bin/env python
import copy

def bubble_sort(card, N):
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
    return " ".join(map(str, card))


def selection_sort(card, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
    return " ".join(map(str, card))


# check method
# insertion sort is a stable sort.
def insertion_sort(card, N):
    for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
    return " ".join(map(str, card))


def value(elem):
    return elem[1]


def main():
    size = int(input())
    line = input().split()
    gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size))

    bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(bubble_ans)
    if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

    selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(selection_ans)
    if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')


if __name__ == '__main__':
    main() import copy copy def bubble_sort(card, N):
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
    return " ".join(map(str, card)) bubble_sort for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
     i range(0, N) range 0 N for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
     j range(N-1, i, -1) range N-1 N 1 i -1 if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
     value(card[j]) < value(card[j-1]) value(card[j]) value card[j] card j value(card[j-1]) value card[j-1] card j-1 j 1 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 return " ".join(map(str, card)) " ".join(map(str, card)) " ".join " " join map(str, card) map str card card card N N def selection_sort(card, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
    return " ".join(map(str, card))


# check method
# insertion sort is a stable sort. selection_sort for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
     i range(0, N) range 0 N minj = i minj i for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
         j range(i, N) range i N if value(card[j]) < value(card[minj]):
                minj = j
         value(card[j]) < value(card[minj]) value(card[j]) value card[j] card j value(card[minj]) value card[minj] card minj 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 return " ".join(map(str, card)) " ".join(map(str, card)) " ".join " " join map(str, card) map str card card card N N def insertion_sort(card, N):
    for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
    return " ".join(map(str, card)) insertion_sort for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
     i range(1, N) range 1 N v = card[i] v card[i] card i j = i - 1 j i - 1 i 1 while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
         j >= 0 and value(card[j]) > value(v) j >= 0 j 0 value(card[j]) > value(v) value(card[j]) value card[j] card j value(v) value v card[j+1] = card[j] card[j+1] card j+1 j 1 card[j] card j j -= 1 j 1 card[j+1] = v card[j+1] card j+1 j 1 v return " ".join(map(str, card)) " ".join(map(str, card)) " ".join " " join map(str, card) map str card card card N N def value(elem):
    return elem[1] value return elem[1] elem[1] elem 1 elem elem def main():
    size = int(input())
    line = input().split()
    gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size))

    bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(bubble_ans)
    if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

    selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(selection_ans)
    if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable') main size = int(input()) size int(input()) int input() input line = input().split() line input().split() ().split () input split gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size)) gold_standard insertion_sort(copy.deepcopy(line), copy.deepcopy(size)) insertion_sort copy.deepcopy(line) copy.deepcopy copy deepcopy line copy.deepcopy(size) copy.deepcopy copy deepcopy size bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size)) bubble_ans bubble_sort(copy.deepcopy(line), copy.deepcopy(size)) bubble_sort copy.deepcopy(line) copy.deepcopy copy deepcopy line copy.deepcopy(size) copy.deepcopy copy deepcopy size print(bubble_ans) print bubble_ans if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

     bubble_ans == gold_standard bubble_ans gold_standard print('Stable') print 'Stable' print('Not stable') print 'Not stable' selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size)) selection_ans selection_sort(copy.deepcopy(line), copy.deepcopy(size)) selection_sort copy.deepcopy(line) copy.deepcopy copy deepcopy line copy.deepcopy(size) copy.deepcopy copy deepcopy size print(selection_ans) print selection_ans if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable') selection_ans == gold_standard selection_ans gold_standard print('Stable') print 'Stable' print('Not stable') print 'Not stable' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def bubble_sort(card, N):
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
    return " ".join(map(str, card)) def bubble_sort(card, N):
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
    return " ".join(map(str, card)) bubble_sort def main():
    size = int(input())
    line = input().split()
    gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size))

    bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(bubble_ans)
    if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

    selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(selection_ans)
    if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable') def main():
    size = int(input())
    line = input().split()
    gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size))

    bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(bubble_ans)
    if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

    selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(selection_ans)
    if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable') main def insertion_sort(card, N):
    for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
    return " ".join(map(str, card)) def insertion_sort(card, N):
    for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
    return " ".join(map(str, card)) insertion_sort def value(elem):
    return elem[1] def value(elem):
    return elem[1] value def selection_sort(card, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
    return " ".join(map(str, card))


# check method
# insertion sort is a stable sort. def selection_sort(card, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
    return " ".join(map(str, card))


# check method
# insertion sort is a stable sort. selection_sort
#!/usr/bin/env python
import copy

def bubble_sort(card, N):
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
    return " ".join(map(str, card))


def selection_sort(card, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
    return " ".join(map(str, card))


# check method
# insertion sort is a stable sort.
def insertion_sort(card, N):
    for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
    return " ".join(map(str, card))


def value(elem):
    return elem[1]


def main():
    size = int(input())
    line = input().split()
    gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size))

    bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(bubble_ans)
    if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

    selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(selection_ans)
    if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')


if __name__ == '__main__':
    main()