def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A

def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A

N= int(input())
A = [str(x) for x in input().split()]
B = [0 for i in range(N)]
for i in range(N):
    B[i] = A[i]
bubble = BubbleSort(A, N)
selection = SelectionSort(B, N)
#print(A, B)
#print(*A)
print(*bubble)
print('Stable')
print(*selection)
if bubble == selection:
    print('Stable')
else:
    print('Not stable') def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A SelectionSort for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
     i range(N) range N minj = i minj i for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
         j range(i, N) range i N if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
         A[j][1:] < A[minj][1:] A[j][1:] [j] A j 1: 1 A[minj][1:] [minj] A minj 1: 1 minj = j minj j A[i], A[minj] = A[minj], A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i return A A A A N N def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A BubbleSort for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

     i range(N) range N for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

     j reversed(range(i+1, N)) reversed range(i+1, N) range i+1 i 1 N if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

     A[j][1:] < A[j-1][1:] A[j][1:] [j] A j 1: 1 A[j-1][1:] [j-1] A j-1 j 1 1: 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j return A A A A N N N= int(input()) N int(input()) int input() input str(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() str(x) str x A = [str(x) for x in input().split()] A [str(x) for x in input().split()] 0 for i in range(N) for i in range(N) i range(N) range N for i in range(N) 0 B = [0 for i in range(N)] B [0 for i in range(N)] for i in range(N):
    B[i] = A[i] i range(N) range N B[i] = A[i] B[i] B i A[i] A i bubble = BubbleSort(A, N) bubble BubbleSort(A, N) BubbleSort A N selection = SelectionSort(B, N) selection SelectionSort(B, N) SelectionSort B N print(*bubble) print *bubble bubble print('Stable') print 'Stable' print(*selection) print *selection selection if bubble == selection:
    print('Stable')
else:
    print('Not stable') bubble == selection bubble selection print('Stable') print 'Stable' print('Not stable') print 'Not stable' A = [str(x) for x in input().split()] [str(x) for x in input().split()] A def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A BubbleSort N= int(input()) int(input()) N B = [0 for i in range(N)] [0 for i in range(N)] B def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A SelectionSort bubble = BubbleSort(A, N) BubbleSort(A, N) bubble selection = SelectionSort(B, N) SelectionSort(B, N) selection
def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A

def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A

N= int(input())
A = [str(x) for x in input().split()]
B = [0 for i in range(N)]
for i in range(N):
    B[i] = A[i]
bubble = BubbleSort(A, N)
selection = SelectionSort(B, N)
#print(A, B)
#print(*A)
print(*bubble)
print('Stable')
print(*selection)
if bubble == selection:
    print('Stable')
else:
    print('Not stable')