def BubbleSort(C, N):
    for i in range(N-1):
        for j in range(N-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 SelectionSort(C, N):
    for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
    return C

def isStable(in_list, out_list):
    N = len(in_list)
    for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
    return True

if __name__ == "__main__":
    N = int(input())
    C = list(map(str, input().split()))
    C1 = C.copy()
    C2 = C.copy()
    Bubble_C = BubbleSort(C1, N)
    Selection_C = SelectionSort(C2, N)

    print(*Bubble_C)
    print('Stable')
    print(*Selection_C)
    if Bubble_C == Selection_C:
        print('Stable')
    else:
        print('Not stable') def BubbleSort(C, N):
    for i in range(N-1):
        for j in range(N-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 BubbleSort for i in range(N-1):
        for j in range(N-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(N-1) range N-1 N 1 for j in range(N-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(N-1, i, -1) range N-1 N 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 N N def SelectionSort(C, N):
    for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
    return C SelectionSort for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
     i range(N) range N min_j = i min_j i for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
         j range(i+1, N) range i+1 i 1 N if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
         int(C[j][1]) < int(C[min_j][1]) int(C[j][1]) int C[j][1] [j] C j 1 int(C[min_j][1]) int C[min_j][1] [min_j] C min_j 1 min_j = j min_j j C[i], C[min_j] = C[min_j], C[i] C[i] C i C[min_j] C min_j C[min_j] C min_j C[i] C i return C C C C N N def isStable(in_list, out_list):
    N = len(in_list)
    for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
    return True isStable N = len(in_list) N len(in_list) len in_list for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
     i_in range(N) range N for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
     j_in range(i_in+1, N) range i_in+1 i_in 1 N for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
     i_out range(N) range N for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
     j_out range(i_out+1, N) range i_out+1 i_out 1 N if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
     (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]) (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) in_list[i_in][1] == in_list[j_in][1] in_list[i_in][1] [i_in] in_list i_in 1 in_list[j_in][1] [j_in] in_list j_in 1 in_list[i_in] == out_list[j_out] in_list[i_in] in_list i_in out_list[j_out] out_list j_out in_list[j_in] == out_list[i_out] in_list[j_in] in_list j_in out_list[i_out] out_list i_out return False False return True True in_list in_list out_list out_list if __name__ == "__main__":
    N = int(input())
    C = list(map(str, input().split()))
    C1 = C.copy()
    C2 = C.copy()
    Bubble_C = BubbleSort(C1, N)
    Selection_C = SelectionSort(C2, N)

    print(*Bubble_C)
    print('Stable')
    print(*Selection_C)
    if Bubble_C == Selection_C:
        print('Stable')
    else:
        print('Not stable') __name__ == "__main__" __name__ "__main__" N = int(input()) N int(input()) int input() input C = list(map(str, input().split())) C list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split C1 = C.copy() C1 C.copy() C.copy C copy C2 = C.copy() C2 C.copy() C.copy C copy Bubble_C = BubbleSort(C1, N) Bubble_C BubbleSort(C1, N) BubbleSort C1 N Selection_C = SelectionSort(C2, N) Selection_C SelectionSort(C2, N) SelectionSort C2 N print(*Bubble_C) print *Bubble_C Bubble_C print('Stable') print 'Stable' print(*Selection_C) print *Selection_C Selection_C if Bubble_C == Selection_C:
        print('Stable')
    else:
        print('Not stable') Bubble_C == Selection_C Bubble_C Selection_C print('Stable') print 'Stable' print('Not stable') print 'Not stable' N = int(input()) int(input()) N Bubble_C = BubbleSort(C1, N) BubbleSort(C1, N) Bubble_C def isStable(in_list, out_list):
    N = len(in_list)
    for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
    return True def isStable(in_list, out_list):
    N = len(in_list)
    for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
    return True isStable C1 = C.copy() C.copy() C1 C = list(map(str, input().split())) list(map(str, input().split())) C C2 = C.copy() C.copy() C2 Selection_C = SelectionSort(C2, N) SelectionSort(C2, N) Selection_C def BubbleSort(C, N):
    for i in range(N-1):
        for j in range(N-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 BubbleSort(C, N):
    for i in range(N-1):
        for j in range(N-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 BubbleSort def SelectionSort(C, N):
    for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
    return C def SelectionSort(C, N):
    for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
    return C SelectionSort
def BubbleSort(C, N):
    for i in range(N-1):
        for j in range(N-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 SelectionSort(C, N):
    for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
    return C

def isStable(in_list, out_list):
    N = len(in_list)
    for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
    return True

if __name__ == "__main__":
    N = int(input())
    C = list(map(str, input().split()))
    C1 = C.copy()
    C2 = C.copy()
    Bubble_C = BubbleSort(C1, N)
    Selection_C = SelectionSort(C2, N)

    print(*Bubble_C)
    print('Stable')
    print(*Selection_C)
    if Bubble_C == Selection_C:
        print('Stable')
    else:
        print('Not stable')
