count = int(input());
data = input().split(" ");

def bubble_sort(data):
    # print(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data);

def selection_sort(data):
    count = len(data);
    # print(data);
    for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data);

def show(data):
    print(" ".join(data));

A = list(data);
bubble_sort(A);
show(A);
print("Stable");

B = list(data);
selection_sort(B);
show(B);
if A == B:
    print("Stable");
else:
    print("Not stable"); count = int(input()) count int(input()) int input() input data = input().split(" ") data input().split(" ") ().split () input split " " def bubble_sort(data):
    # print(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data); bubble_sort count = len(data) count len(data) len data for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data); i range(count) range count for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data); j range(count - 1, i, -1) range count - 1 count 1 i -1 if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data); data[j][1] < data[j - 1][1] data[j][1] [j] data j 1 data[j - 1][1] [j - 1] data j - 1 j 1 1 data[j], data[j - 1] = data[j - 1], data[j] data[j] data j data[j - 1] data j - 1 j 1 data[j - 1] data j - 1 j 1 data[j] data j data data def selection_sort(data):
    count = len(data);
    # print(data);
    for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data); selection_sort count = len(data) count len(data) len data for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data); i range(count - 1) range count - 1 count 1 minI = i minI i for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
         j range(i + 1, count) range i + 1 i 1 count if data[j][1] < data[minI][1]:
                minI = j;
         data[j][1] < data[minI][1] data[j][1] [j] data j 1 data[minI][1] [minI] data minI 1 minI = j minI j if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data); i != minI i minI data[i], data[minI] = data[minI], data[i] data[i] data i data[minI] data minI data[minI] data minI data[i] data i data data def show(data):
    print(" ".join(data)); show print(" ".join(data)) print " ".join(data) " ".join " " join data data data A = list(data) A list(data) list data bubble_sort(A) bubble_sort A show(A) show A print("Stable") print "Stable" B = list(data) B list(data) list data selection_sort(B) selection_sort B show(B) show B if A == B:
    print("Stable");
else:
    print("Not stable"); A == B A B print("Stable") print "Stable" print("Not stable") print "Not stable" B = list(data) list(data) B def bubble_sort(data):
    # print(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data); def bubble_sort(data):
    # print(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data); bubble_sort def show(data):
    print(" ".join(data)); def show(data):
    print(" ".join(data)); show count = int(input()) int(input()) count def selection_sort(data):
    count = len(data);
    # print(data);
    for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data); def selection_sort(data):
    count = len(data);
    # print(data);
    for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data); selection_sort A = list(data) list(data) A data = input().split(" ") input().split(" ") data
count = int(input());
data = input().split(" ");

def bubble_sort(data):
    # print(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data);

def selection_sort(data):
    count = len(data);
    # print(data);
    for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data);

def show(data):
    print(" ".join(data));

A = list(data);
bubble_sort(A);
show(A);
print("Stable");

B = list(data);
selection_sort(B);
show(B);
if A == B:
    print("Stable");
else:
    print("Not stable");
