import copy

def bubble_sort(C):
    for i in range(len(C)):
        for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C

def selection_sort(C):
    for i in range(len(C)):
        minj = i
        for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
        C[minj], C[i], = C[i], C[minj]
    return C

if __name__ == '__main__':
    n = int(input())
    B = input().split()
    C_bubble = bubble_sort(copy.deepcopy(B))
    print(*C_bubble)
    print('Stable')
    C_selection = selection_sort(copy.deepcopy(B))
    print(*C_selection)
    if C_bubble == C_selection:
        print('Stable')
    else:
        print('Not stable')
 import copy copy def bubble_sort(C):
    for i in range(len(C)):
        for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C bubble_sort for i in range(len(C)):
        for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
     i range(len(C)) range len(C) len C for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
     j range(len(C)-1, i, -1) range len(C)-1 len(C) len C 1 i -1 if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
     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 C[j], C[j-1] = C[j-1], C[j] C[j] C j C[j-1] C j-1 j 1 C[j-1] C j-1 j 1 C[j] C j return C C C C def selection_sort(C):
    for i in range(len(C)):
        minj = i
        for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
        C[minj], C[i], = C[i], C[minj]
    return C selection_sort for i in range(len(C)):
        minj = i
        for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
        C[minj], C[i], = C[i], C[minj]
     i range(len(C)) range len(C) len C minj = i minj i for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
         j range(i, len(C)) range i len(C) len C if int(C[minj][1]) > int(C[j][1]):
                minj = j
         int(C[minj][1]) > int(C[j][1]) int(C[minj][1]) int C[minj][1] [minj] C minj 1 int(C[j][1]) int C[j][1] [j] C j 1 minj = j minj j C[minj], C[i], = C[i], C[minj] C[minj] C minj C[i] C i C[i] C i C[minj] C minj return C C C C if __name__ == '__main__':
    n = int(input())
    B = input().split()
    C_bubble = bubble_sort(copy.deepcopy(B))
    print(*C_bubble)
    print('Stable')
    C_selection = selection_sort(copy.deepcopy(B))
    print(*C_selection)
    if C_bubble == C_selection:
        print('Stable')
    else:
        print('Not stable') __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input B = input().split() B input().split() ().split () input split C_bubble = bubble_sort(copy.deepcopy(B)) C_bubble bubble_sort(copy.deepcopy(B)) bubble_sort copy.deepcopy(B) copy.deepcopy copy deepcopy B print(*C_bubble) print *C_bubble C_bubble print('Stable') print 'Stable' C_selection = selection_sort(copy.deepcopy(B)) C_selection selection_sort(copy.deepcopy(B)) selection_sort copy.deepcopy(B) copy.deepcopy copy deepcopy B print(*C_selection) print *C_selection C_selection if C_bubble == C_selection:
        print('Stable')
    else:
        print('Not stable') C_bubble == C_selection C_bubble C_selection print('Stable') print 'Stable' print('Not stable') print 'Not stable' n = int(input()) int(input()) n C_selection = selection_sort(copy.deepcopy(B)) selection_sort(copy.deepcopy(B)) C_selection B = input().split() input().split() B C_bubble = bubble_sort(copy.deepcopy(B)) bubble_sort(copy.deepcopy(B)) C_bubble def bubble_sort(C):
    for i in range(len(C)):
        for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C def bubble_sort(C):
    for i in range(len(C)):
        for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C bubble_sort def selection_sort(C):
    for i in range(len(C)):
        minj = i
        for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
        C[minj], C[i], = C[i], C[minj]
    return C def selection_sort(C):
    for i in range(len(C)):
        minj = i
        for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
        C[minj], C[i], = C[i], C[minj]
    return C selection_sort
import copy

def bubble_sort(C):
    for i in range(len(C)):
        for j in range(len(C)-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C

def selection_sort(C):
    for i in range(len(C)):
        minj = i
        for j in range(i, len(C)):
            if int(C[minj][1]) > int(C[j][1]):
                minj = j
        C[minj], C[i], = C[i], C[minj]
    return C

if __name__ == '__main__':
    n = int(input())
    B = input().split()
    C_bubble = bubble_sort(copy.deepcopy(B))
    print(*C_bubble)
    print('Stable')
    C_selection = selection_sort(copy.deepcopy(B))
    print(*C_selection)
    if C_bubble == C_selection:
        print('Stable')
    else:
        print('Not stable')

