N = int(input())
C1 = input().split()
C2 = C1[:]

def bubbleSort(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]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        i += 1
    return C

def selectionSort(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
        if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
        i += 1
    return C

bubbleSort_result = ' '.join(bubbleSort(C1, N))
selectionSort_result = ' '.join(selectionSort(C2, N))

print(bubbleSort_result)
print('Stable')
print(selectionSort_result)
if bubbleSort_result == selectionSort_result:
    print('Stable')
else:
    print('Not stable') N = int(input()) N int(input()) int input() input C1 = input().split() C1 input().split() ().split () input split C2 = C1[:] C2 C1[:] C1 : def bubbleSort(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]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        i += 1
    return C bubbleSort for i in range(N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        i += 1
     i range(N) range N for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
         j range(N-1, i, -1) range N-1 N 1 i -1 if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
         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 tmp = C[j] tmp C[j] C j C[j] = C[j-1] C[j] C j C[j-1] C j-1 j 1 C[j-1] = tmp C[j-1] C j-1 j 1 tmp i += 1 i 1 return C C C C N N def selectionSort(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
        if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
        i += 1
    return C selectionSort for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
        i += 1
     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 if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
         minj != i minj i tmp = C[minj] tmp C[minj] C minj C[minj] = C[i] C[minj] C minj C[i] C i C[i] = tmp C[i] C i tmp i += 1 i 1 return C C C C N N bubbleSort_result = ' '.join(bubbleSort(C1, N)) bubbleSort_result ' '.join(bubbleSort(C1, N)) ' '.join ' ' join bubbleSort(C1, N) bubbleSort C1 N selectionSort_result = ' '.join(selectionSort(C2, N)) selectionSort_result ' '.join(selectionSort(C2, N)) ' '.join ' ' join selectionSort(C2, N) selectionSort C2 N print(bubbleSort_result) print bubbleSort_result print('Stable') print 'Stable' print(selectionSort_result) print selectionSort_result if bubbleSort_result == selectionSort_result:
    print('Stable')
else:
    print('Not stable') bubbleSort_result == selectionSort_result bubbleSort_result selectionSort_result print('Stable') print 'Stable' print('Not stable') print 'Not stable' bubbleSort_result = ' '.join(bubbleSort(C1, N)) ' '.join(bubbleSort(C1, N)) bubbleSort_result def selectionSort(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
        if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
        i += 1
    return C def selectionSort(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
        if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
        i += 1
    return C selectionSort C1 = input().split() input().split() C1 selectionSort_result = ' '.join(selectionSort(C2, N)) ' '.join(selectionSort(C2, N)) selectionSort_result def bubbleSort(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]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        i += 1
    return C def bubbleSort(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]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        i += 1
    return C bubbleSort N = int(input()) int(input()) N C2 = C1[:] C1[:] C2
N = int(input())
C1 = input().split()
C2 = C1[:]

def bubbleSort(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]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        i += 1
    return C

def selectionSort(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
        if minj != i:
            tmp = C[minj]
            C[minj] = C[i]
            C[i] = tmp
        i += 1
    return C

bubbleSort_result = ' '.join(bubbleSort(C1, N))
selectionSort_result = ' '.join(selectionSort(C2, N))

print(bubbleSort_result)
print('Stable')
print(selectionSort_result)
if bubbleSort_result == selectionSort_result:
    print('Stable')
else:
    print('Not stable')