def selection_sort(array):
    count_swap = 0
    for i in range(len(array)):
        minj = i
        for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
        if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
    return count_swap

def bubble_sort(array):
    isEnd = False
    count_swap = 0
    while isEnd is False:
        isEnd = True
        for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
    return count_swap

def print_array(array):
     print(str(array)[1:-1].replace(', ', ' ').replace('\'', ''))

def num(s):
    # print(s[1])
    return int(s[1])

def main():
    N = int(input())
    array = [s for s in input().split(' ')]
    array2 = [i for i in array]
    # print(array)
    bubble_sort(array)
    print_array(array)
    print('Stable')
    selection_sort(array2)
    print_array(array2)
    if array == array2:
        print('Stable')
    else:
        print('Not stable')

if __name__ == '__main__':
    main() def selection_sort(array):
    count_swap = 0
    for i in range(len(array)):
        minj = i
        for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
        if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
    return count_swap selection_sort count_swap = 0 count_swap 0 for i in range(len(array)):
        minj = i
        for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
        if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
     i range(len(array)) range len(array) len array minj = i minj i for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
         j range(i + 1,len(array)) range i + 1 i 1 len(array) len array if num(array[j]) < num(array[minj]):
                minj = j
         num(array[j]) < num(array[minj]) num(array[j]) num array[j] array j num(array[minj]) num array[minj] array minj minj = j minj j if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
     num(array[minj]) is not num(array[i]) num(array[minj]) num array[minj] array minj num(array[i]) num array[i] array i tmp = array[minj] tmp array[minj] array minj array[minj] = array[i] array[minj] array minj array[i] array i array[i] = tmp array[i] array i tmp count_swap += 1 count_swap 1 return count_swap count_swap array array def bubble_sort(array):
    isEnd = False
    count_swap = 0
    while isEnd is False:
        isEnd = True
        for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
    return count_swap bubble_sort isEnd = False isEnd False count_swap = 0 count_swap 0 while isEnd is False:
        isEnd = True
        for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
     isEnd is False isEnd False isEnd = True isEnd True for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
     j reversed(range(1,len(array))) reversed range(1,len(array)) range 1 len(array) len array if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
     num(array[j - 1]) > num(array[j]) num(array[j - 1]) num array[j - 1] array j - 1 j 1 num(array[j]) num array[j] array j tmp = array[j - 1] tmp array[j - 1] array j - 1 j 1 array[j - 1] = array[j] array[j - 1] array j - 1 j 1 array[j] array j array[j] = tmp array[j] array j tmp count_swap += 1 count_swap 1 isEnd = False isEnd False return count_swap count_swap array array def print_array(array):
     print(str(array)[1:-1].replace(', ', ' ').replace('\'', '')) print_array print(str(array)[1:-1].replace(', ', ' ').replace('\'', '')) print str(array)[1:-1].replace(', ', ' ').replace('\'', '') [1:-1].replace(', ', ' ').replace [1:-1].replace(', ', ' ') [1:-1].replace [1:-1] (array) str array 1:-1 1 -1 replace ', ' ' ' replace '\'' '' array array def num(s):
    # print(s[1])
    return int(s[1]) num return int(s[1]) int(s[1]) int s[1] s 1 s s def main():
    N = int(input())
    array = [s for s in input().split(' ')]
    array2 = [i for i in array]
    # print(array)
    bubble_sort(array)
    print_array(array)
    print('Stable')
    selection_sort(array2)
    print_array(array2)
    if array == array2:
        print('Stable')
    else:
        print('Not stable') main N = int(input()) N int(input()) int input() input s for s in input().split(' ') for s in input().split(' ') s input().split(' ') ().split () input split ' ' for s in input().split(' ') s array = [s for s in input().split(' ')] array [s for s in input().split(' ')] i for i in array for i in array i array for i in array i array2 = [i for i in array] array2 [i for i in array] bubble_sort(array) bubble_sort array print_array(array) print_array array print('Stable') print 'Stable' selection_sort(array2) selection_sort array2 print_array(array2) print_array array2 if array == array2:
        print('Stable')
    else:
        print('Not stable') array == array2 array array2 print('Stable') print 'Stable' print('Not stable') print 'Not stable' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def selection_sort(array):
    count_swap = 0
    for i in range(len(array)):
        minj = i
        for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
        if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
    return count_swap def selection_sort(array):
    count_swap = 0
    for i in range(len(array)):
        minj = i
        for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
        if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
    return count_swap selection_sort def print_array(array):
     print(str(array)[1:-1].replace(', ', ' ').replace('\'', '')) def print_array(array):
     print(str(array)[1:-1].replace(', ', ' ').replace('\'', '')) print_array def main():
    N = int(input())
    array = [s for s in input().split(' ')]
    array2 = [i for i in array]
    # print(array)
    bubble_sort(array)
    print_array(array)
    print('Stable')
    selection_sort(array2)
    print_array(array2)
    if array == array2:
        print('Stable')
    else:
        print('Not stable') def main():
    N = int(input())
    array = [s for s in input().split(' ')]
    array2 = [i for i in array]
    # print(array)
    bubble_sort(array)
    print_array(array)
    print('Stable')
    selection_sort(array2)
    print_array(array2)
    if array == array2:
        print('Stable')
    else:
        print('Not stable') main def bubble_sort(array):
    isEnd = False
    count_swap = 0
    while isEnd is False:
        isEnd = True
        for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
    return count_swap def bubble_sort(array):
    isEnd = False
    count_swap = 0
    while isEnd is False:
        isEnd = True
        for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
    return count_swap bubble_sort def num(s):
    # print(s[1])
    return int(s[1]) def num(s):
    # print(s[1])
    return int(s[1]) num
def selection_sort(array):
    count_swap = 0
    for i in range(len(array)):
        minj = i
        for j in range(i + 1,len(array)):
            if num(array[j]) < num(array[minj]):
                minj = j
        if num(array[minj]) is not num(array[i]):
            tmp = array[minj]
            array[minj] = array[i]
            array[i] = tmp
            count_swap += 1
    return count_swap

def bubble_sort(array):
    isEnd = False
    count_swap = 0
    while isEnd is False:
        isEnd = True
        for j in reversed(range(1,len(array))):
            if num(array[j - 1]) > num(array[j]):
                tmp = array[j - 1]
                array[j - 1] = array[j]
                array[j] = tmp
                count_swap += 1
                isEnd = False
    return count_swap

def print_array(array):
     print(str(array)[1:-1].replace(', ', ' ').replace('\'', ''))

def num(s):
    # print(s[1])
    return int(s[1])

def main():
    N = int(input())
    array = [s for s in input().split(' ')]
    array2 = [i for i in array]
    # print(array)
    bubble_sort(array)
    print_array(array)
    print('Stable')
    selection_sort(array2)
    print_array(array2)
    if array == array2:
        print('Stable')
    else:
        print('Not stable')

if __name__ == '__main__':
    main()