def selection_sort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[minj][-1]):
                minj = j
        temp = c[i]
        c[i] = c[minj]
        c[minj] = temp
    return c


def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
    return c


def is_stable(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            print('Not stable')
            return
    print('Stable')


def main():
    n = int(input())
    nums = input().split(' ')
    bubble_nums = [i for i in nums]
    select_nums = [i for i in nums]
    bubble_nums = bubble_sort(bubble_nums, n)
    select_nums = selection_sort(select_nums, n)

    print(' '.join(bubble_nums))
    print('Stable')
    print(' '.join(select_nums))
    is_stable(bubble_nums, select_nums)


if __name__ == "__main__":
    main()
 def selection_sort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[minj][-1]):
                minj = j
        temp = c[i]
        c[i] = c[minj]
        c[minj] = temp
    return c selection_sort for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[minj][-1]):
                minj = j
        temp = c[i]
        c[i] = c[minj]
        c[minj] = temp
     i range(n) range 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 temp = c[i] temp c[i] c i c[i] = c[minj] c[i] c i c[minj] c minj c[minj] = temp c[minj] c minj temp return c c c c n n def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
    return c bubble_sort for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
     i range(n) range n for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
     j range(n-1, i, -1) range n-1 n 1 i -1 if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
     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 temp = c[j] temp c[j] c j c[j] = c[j-1] c[j] c j c[j-1] c j-1 j 1 c[j-1] = temp c[j-1] c j-1 j 1 temp return c c c c n n def is_stable(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            print('Not stable')
            return
    print('Stable') is_stable for i in range(len(a)):
        if a[i] != b[i]:
            print('Not stable')
            return
     i range(len(a)) range len(a) len a if a[i] != b[i]:
            print('Not stable')
            return
     a[i] != b[i] a[i] a i b[i] b i print('Not stable') print 'Not stable' return print('Stable') print 'Stable' a a b b def main():
    n = int(input())
    nums = input().split(' ')
    bubble_nums = [i for i in nums]
    select_nums = [i for i in nums]
    bubble_nums = bubble_sort(bubble_nums, n)
    select_nums = selection_sort(select_nums, n)

    print(' '.join(bubble_nums))
    print('Stable')
    print(' '.join(select_nums))
    is_stable(bubble_nums, select_nums) main n = int(input()) n int(input()) int input() input nums = input().split(' ') nums input().split(' ') ().split () input split ' ' i for i in nums for i in nums i nums for i in nums i bubble_nums = [i for i in nums] bubble_nums [i for i in nums] i for i in nums for i in nums i nums for i in nums i select_nums = [i for i in nums] select_nums [i for i in nums] bubble_nums = bubble_sort(bubble_nums, n) bubble_nums bubble_sort(bubble_nums, n) bubble_sort bubble_nums n select_nums = selection_sort(select_nums, n) select_nums selection_sort(select_nums, n) selection_sort select_nums n print(' '.join(bubble_nums)) print ' '.join(bubble_nums) ' '.join ' ' join bubble_nums print('Stable') print 'Stable' print(' '.join(select_nums)) print ' '.join(select_nums) ' '.join ' ' join select_nums is_stable(bubble_nums, select_nums) is_stable bubble_nums select_nums if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
    return c def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
    return c bubble_sort def is_stable(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            print('Not stable')
            return
    print('Stable') def is_stable(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            print('Not stable')
            return
    print('Stable') is_stable def main():
    n = int(input())
    nums = input().split(' ')
    bubble_nums = [i for i in nums]
    select_nums = [i for i in nums]
    bubble_nums = bubble_sort(bubble_nums, n)
    select_nums = selection_sort(select_nums, n)

    print(' '.join(bubble_nums))
    print('Stable')
    print(' '.join(select_nums))
    is_stable(bubble_nums, select_nums) def main():
    n = int(input())
    nums = input().split(' ')
    bubble_nums = [i for i in nums]
    select_nums = [i for i in nums]
    bubble_nums = bubble_sort(bubble_nums, n)
    select_nums = selection_sort(select_nums, n)

    print(' '.join(bubble_nums))
    print('Stable')
    print(' '.join(select_nums))
    is_stable(bubble_nums, select_nums) main def selection_sort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[minj][-1]):
                minj = j
        temp = c[i]
        c[i] = c[minj]
        c[minj] = temp
    return c def selection_sort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[minj][-1]):
                minj = j
        temp = c[i]
        c[i] = c[minj]
        c[minj] = temp
    return c selection_sort
def selection_sort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[minj][-1]):
                minj = j
        temp = c[i]
        c[i] = c[minj]
        c[minj] = temp
    return c


def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(c[j-1][-1]):
                temp = c[j]
                c[j] = c[j-1]
                c[j-1] = temp
    return c


def is_stable(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            print('Not stable')
            return
    print('Stable')


def main():
    n = int(input())
    nums = input().split(' ')
    bubble_nums = [i for i in nums]
    select_nums = [i for i in nums]
    bubble_nums = bubble_sort(bubble_nums, n)
    select_nums = selection_sort(select_nums, n)

    print(' '.join(bubble_nums))
    print('Stable')
    print(' '.join(select_nums))
    is_stable(bubble_nums, select_nums)


if __name__ == "__main__":
    main()

