def main():
    n = int(input())
    cards = list(map(str, input().split()))
    bubbleSortedCards = cards[:]
    selectionSortedCards = cards[:]


    bubbleSort(bubbleSortedCards, n)
    print(' '.join(map(str, bubbleSortedCards)))
    print('Stable')

    selectionSort(selectionSortedCards, n)
    print(' '.join(map(str, selectionSortedCards)))
    print(isStable(bubbleSortedCards, selectionSortedCards, n))


def bubbleSort(numbers, n):
    for i in range(n - 1, 0, -1):
        for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]

def selectionSort(numbers, n):
    minj = 0

    for i in range(n):
        minj = i
        for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

        if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i]

def isStable(bubbleSortedCards, selectionSortedCards, n):
    for i in range(n):
        if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

    return 'Stable'

if __name__ == '__main__':
    main()
 def main():
    n = int(input())
    cards = list(map(str, input().split()))
    bubbleSortedCards = cards[:]
    selectionSortedCards = cards[:]


    bubbleSort(bubbleSortedCards, n)
    print(' '.join(map(str, bubbleSortedCards)))
    print('Stable')

    selectionSort(selectionSortedCards, n)
    print(' '.join(map(str, selectionSortedCards)))
    print(isStable(bubbleSortedCards, selectionSortedCards, n)) main n = int(input()) n int(input()) int input() input cards = list(map(str, input().split())) cards list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split bubbleSortedCards = cards[:] bubbleSortedCards cards[:] cards : selectionSortedCards = cards[:] selectionSortedCards cards[:] cards : bubbleSort(bubbleSortedCards, n) bubbleSort bubbleSortedCards n print(' '.join(map(str, bubbleSortedCards))) print ' '.join(map(str, bubbleSortedCards)) ' '.join ' ' join map(str, bubbleSortedCards) map str bubbleSortedCards print('Stable') print 'Stable' selectionSort(selectionSortedCards, n) selectionSort selectionSortedCards n print(' '.join(map(str, selectionSortedCards))) print ' '.join(map(str, selectionSortedCards)) ' '.join ' ' join map(str, selectionSortedCards) map str selectionSortedCards print(isStable(bubbleSortedCards, selectionSortedCards, n)) print isStable(bubbleSortedCards, selectionSortedCards, n) isStable bubbleSortedCards selectionSortedCards n def bubbleSort(numbers, n):
    for i in range(n - 1, 0, -1):
        for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] bubbleSort for i in range(n - 1, 0, -1):
        for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] i range(n - 1, 0, -1) range n - 1 n 1 0 -1 for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] j range(i) range i if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] int(numbers[j][1]) > int(numbers[j + 1][1]) int(numbers[j][1]) int numbers[j][1] [j] numbers j 1 int(numbers[j + 1][1]) int numbers[j + 1][1] [j + 1] numbers j + 1 j 1 1 numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] numbers[j] numbers j numbers[j + 1] numbers j + 1 j 1 numbers[j + 1] numbers j + 1 j 1 numbers[j] numbers j numbers numbers n n def selectionSort(numbers, n):
    minj = 0

    for i in range(n):
        minj = i
        for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

        if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i] selectionSort minj = 0 minj 0 for i in range(n):
        minj = i
        for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

        if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i] i range(n) range n minj = i minj i for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

         j range(i, n, 1) range i n 1 if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

         int(numbers[j][1]) < int(numbers[minj][1]) int(numbers[j][1]) int numbers[j][1] [j] numbers j 1 int(numbers[minj][1]) int numbers[minj][1] [minj] numbers minj 1 minj = j minj j if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i] i != minj i minj numbers[i], numbers[minj] = numbers[minj], numbers[i] numbers[i] numbers i numbers[minj] numbers minj numbers[minj] numbers minj numbers[i] numbers i numbers numbers n n def isStable(bubbleSortedCards, selectionSortedCards, n):
    for i in range(n):
        if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

    return 'Stable' isStable for i in range(n):
        if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

     i range(n) range n if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

     bubbleSortedCards[i] != selectionSortedCards[i] bubbleSortedCards[i] bubbleSortedCards i selectionSortedCards[i] selectionSortedCards i return 'Not stable' 'Not stable' return 'Stable' 'Stable' bubbleSortedCards bubbleSortedCards selectionSortedCards selectionSortedCards n n if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def bubbleSort(numbers, n):
    for i in range(n - 1, 0, -1):
        for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] def bubbleSort(numbers, n):
    for i in range(n - 1, 0, -1):
        for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] bubbleSort def isStable(bubbleSortedCards, selectionSortedCards, n):
    for i in range(n):
        if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

    return 'Stable' def isStable(bubbleSortedCards, selectionSortedCards, n):
    for i in range(n):
        if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

    return 'Stable' isStable def main():
    n = int(input())
    cards = list(map(str, input().split()))
    bubbleSortedCards = cards[:]
    selectionSortedCards = cards[:]


    bubbleSort(bubbleSortedCards, n)
    print(' '.join(map(str, bubbleSortedCards)))
    print('Stable')

    selectionSort(selectionSortedCards, n)
    print(' '.join(map(str, selectionSortedCards)))
    print(isStable(bubbleSortedCards, selectionSortedCards, n)) def main():
    n = int(input())
    cards = list(map(str, input().split()))
    bubbleSortedCards = cards[:]
    selectionSortedCards = cards[:]


    bubbleSort(bubbleSortedCards, n)
    print(' '.join(map(str, bubbleSortedCards)))
    print('Stable')

    selectionSort(selectionSortedCards, n)
    print(' '.join(map(str, selectionSortedCards)))
    print(isStable(bubbleSortedCards, selectionSortedCards, n)) main def selectionSort(numbers, n):
    minj = 0

    for i in range(n):
        minj = i
        for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

        if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i] def selectionSort(numbers, n):
    minj = 0

    for i in range(n):
        minj = i
        for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

        if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i] selectionSort
def main():
    n = int(input())
    cards = list(map(str, input().split()))
    bubbleSortedCards = cards[:]
    selectionSortedCards = cards[:]


    bubbleSort(bubbleSortedCards, n)
    print(' '.join(map(str, bubbleSortedCards)))
    print('Stable')

    selectionSort(selectionSortedCards, n)
    print(' '.join(map(str, selectionSortedCards)))
    print(isStable(bubbleSortedCards, selectionSortedCards, n))


def bubbleSort(numbers, n):
    for i in range(n - 1, 0, -1):
        for j in range(i):
            if int(numbers[j][1]) > int(numbers[j + 1][1]):
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]

def selectionSort(numbers, n):
    minj = 0

    for i in range(n):
        minj = i
        for j in range(i, n, 1):
            if int(numbers[j][1]) < int(numbers[minj][1]):
                minj = j

        if i != minj:
            numbers[i], numbers[minj] = numbers[minj], numbers[i]

def isStable(bubbleSortedCards, selectionSortedCards, n):
    for i in range(n):
        if bubbleSortedCards[i] != selectionSortedCards[i]:
            return 'Not stable'

    return 'Stable'

if __name__ == '__main__':
    main()

