import copy

def bubbleSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
    return C

def selectionSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
    return C


N = int(input())
cards = input().split()

CB = bubbleSort(cards)
CS = selectionSort(cards)
print(' '.join(CB))
print('Stable')
print(' '.join(CS))
if CB == CS:
    print('Stable')
else:
    print('Not stable') import copy copy def bubbleSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
    return C bubbleSort C = copy.copy(cards) C copy.copy(cards) copy.copy copy copy cards for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
     i range(0, len(C)) range 0 len(C) len C for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
     j range(len(C) - 1, i, -1) range len(C) - 1 len(C) len C 1 i -1 if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
     C[j][1] < C[j-1][1] C[j][1] [j] C j 1 C[j-1][1] [j-1] C j-1 j 1 1 C[j-1], C[j] = C[j], C[j-1] C[j-1] C j-1 j 1 C[j] C j C[j] C j C[j-1] C j-1 j 1 return C C cards cards def selectionSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
    return C selectionSort C = copy.copy(cards) C copy.copy(cards) copy.copy copy copy cards for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
     i range(0, len(C)) range 0 len(C) len C min = i min i for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
         j range(i, len(C)) range i len(C) len C if C[j][1] < C[min][1]:
                min = j
         C[j][1] < C[min][1] C[j][1] [j] C j 1 C[min][1] [min] C min 1 min = j min j C[i], C[min] = C[min], C[i] C[i] C i C[min] C min C[min] C min C[i] C i return C C cards cards N = int(input()) N int(input()) int input() input cards = input().split() cards input().split() ().split () input split CB = bubbleSort(cards) CB bubbleSort(cards) bubbleSort cards CS = selectionSort(cards) CS selectionSort(cards) selectionSort cards print(' '.join(CB)) print ' '.join(CB) ' '.join ' ' join CB print('Stable') print 'Stable' print(' '.join(CS)) print ' '.join(CS) ' '.join ' ' join CS if CB == CS:
    print('Stable')
else:
    print('Not stable') CB == CS CB CS print('Stable') print 'Stable' print('Not stable') print 'Not stable' CS = selectionSort(cards) selectionSort(cards) CS CB = bubbleSort(cards) bubbleSort(cards) CB def bubbleSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
    return C def bubbleSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
    return C bubbleSort def selectionSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
    return C def selectionSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
    return C selectionSort N = int(input()) int(input()) N cards = input().split() input().split() cards
import copy

def bubbleSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
    return C

def selectionSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
    return C


N = int(input())
cards = input().split()

CB = bubbleSort(cards)
CS = selectionSort(cards)
print(' '.join(CB))
print('Stable')
print(' '.join(CS))
if CB == CS:
    print('Stable')
else:
    print('Not stable')