import copy

n = int(input())
A = list (map(str, input().split()))
B = copy.copy(A) 

def BubbleSort_dict(A, n):
    flag = 1    
    while flag:
        flag = 0
        for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
    return A
    
def SelectionSort_dict(A, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
    return A

A1 = BubbleSort_dict(A, n)
A2 = SelectionSort_dict(B, n)

print(' '.join(A1))
print("Stable")
print(' '.join(A2))
if A1 == A2:
    print("Stable")
else:
    print("Not stable") import copy copy n = int(input()) n int(input()) int input() input A = list (map(str, input().split())) A list (map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split B = copy.copy(A) B copy.copy(A) copy.copy copy copy A def BubbleSort_dict(A, n):
    flag = 1    
    while flag:
        flag = 0
        for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
    return A
     BubbleSort_dict flag = 1 flag 1 while flag:
        flag = 0
        for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
     flag flag = 0 flag 0 for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
     i reversed(range(n-1)) reversed range(n-1) range n-1 n 1 if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
     int(A[i][1]) > int(A[i+1][1]) int(A[i][1]) int A[i][1] [i] A i 1 int(A[i+1][1]) int A[i+1][1] [i+1] A i+1 i 1 1 a = A[i] a A[i] A i A[i] = A[i+1] A[i] A i A[i+1] A i+1 i 1 A[i+1] = a A[i+1] A i+1 i 1 a flag = 1 flag 1 return A A A A n n def SelectionSort_dict(A, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
    return A SelectionSort_dict for i in range(n):
        minj = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
     i range(n) range n minj = i minj i for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
         j range(i, n) range i n if int(A[j][1]) < int(A[minj][1]):
                minj = j
         int(A[j][1]) < int(A[minj][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[minj][1]) int A[minj][1] [minj] A minj 1 minj = j minj j if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
     i != minj i minj a = A[i] a A[i] A i A[i] = A[minj] A[i] A i A[minj] A minj A[minj] = a A[minj] A minj a return A A A A n n A1 = BubbleSort_dict(A, n) A1 BubbleSort_dict(A, n) BubbleSort_dict A n A2 = SelectionSort_dict(B, n) A2 SelectionSort_dict(B, n) SelectionSort_dict B n print(' '.join(A1)) print ' '.join(A1) ' '.join ' ' join A1 print("Stable") print "Stable" print(' '.join(A2)) print ' '.join(A2) ' '.join ' ' join A2 if A1 == A2:
    print("Stable")
else:
    print("Not stable") A1 == A2 A1 A2 print("Stable") print "Stable" print("Not stable") print "Not stable" B = copy.copy(A) copy.copy(A) B def BubbleSort_dict(A, n):
    flag = 1    
    while flag:
        flag = 0
        for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
    return A
     def BubbleSort_dict(A, n):
    flag = 1    
    while flag:
        flag = 0
        for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
    return A
     BubbleSort_dict def SelectionSort_dict(A, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
    return A def SelectionSort_dict(A, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
    return A SelectionSort_dict A2 = SelectionSort_dict(B, n) SelectionSort_dict(B, n) A2 n = int(input()) int(input()) n A1 = BubbleSort_dict(A, n) BubbleSort_dict(A, n) A1 A = list (map(str, input().split())) list (map(str, input().split())) A
import copy

n = int(input())
A = list (map(str, input().split()))
B = copy.copy(A) 

def BubbleSort_dict(A, n):
    flag = 1    
    while flag:
        flag = 0
        for i in reversed(range(n-1)):
            if int(A[i][1]) > int(A[i+1][1]):
                a = A[i]
                A[i] = A[i+1]
                A[i+1] = a
                flag = 1
    return A
    
def SelectionSort_dict(A, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            a = A[i]
            A[i] = A[minj]
            A[minj] = a
    return A

A1 = BubbleSort_dict(A, n)
A2 = SelectionSort_dict(B, n)

print(' '.join(A1))
print("Stable")
print(' '.join(A2))
if A1 == A2:
    print("Stable")
else:
    print("Not stable")
