#coding: UTF-8

N = int(input())
A = input()
#A = list(map(int, input().split()))
IN1 = [None] * N
IN2 = [None] * N
i=0


for a in A.split():
    tmp = int(a.lstrip("SHCD"))
    IN1[i] = [tmp, i, a]
    IN2[i] = [tmp, i, a]
    i+=1

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

def InsertionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp

def StableCheck(A):
    tmp = [0,0]
    for t in A:
        if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
        tmp = t
    return True


BubbleSort(IN1,N)
InsertionSort(IN2,N)

for i in range(N - 1):
    print(IN1[i][2],end=' ')
print(IN1[N - 1][2])
if(StableCheck(IN1)):print("Stable")
else:print("Not stable")

for i in range(N - 1):
    print(IN2[i][2],end=' ')
print(IN2[N - 1][2])
if(StableCheck(IN2)):print("Stable")
else:print("Not stable") N = int(input()) N int(input()) int input() input A = input() A input() input IN1 = [None] * N IN1 [None] * N [None] None N IN2 = [None] * N IN2 [None] * N [None] None N i=0 i 0 for a in A.split():
    tmp = int(a.lstrip("SHCD"))
    IN1[i] = [tmp, i, a]
    IN2[i] = [tmp, i, a]
    i+=1 a A.split() A.split A split tmp = int(a.lstrip("SHCD")) tmp int(a.lstrip("SHCD")) int a.lstrip("SHCD") a.lstrip a lstrip "SHCD" IN1[i] = [tmp, i, a] IN1[i] IN1 i [tmp, i, a] tmp i a IN2[i] = [tmp, i, a] IN2[i] IN2 i [tmp, i, a] tmp i a i+=1 i 1 def BubbleSort(A,N):
    for i in range(N - 1):
        for j in range(N - 1, i,-1):
            if A[j][0] < A[j - 1][0]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp BubbleSort for i in range(N - 1):
        for j in range(N - 1, i,-1):
            if A[j][0] < A[j - 1][0]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp i range(N - 1) range N - 1 N 1 for j in range(N - 1, i,-1):
            if A[j][0] < A[j - 1][0]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp j range(N - 1, i,-1) range N - 1 N 1 i -1 if A[j][0] < A[j - 1][0]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp A[j][0] < A[j - 1][0] A[j][0] [j] A j 0 A[j - 1][0] [j - 1] A j - 1 j 1 0 tmp = A[j] tmp A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = tmp A[j - 1] A j - 1 j 1 tmp A A N N def InsertionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp InsertionSort for i in range(0,N):
        minj = i
        for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp i range(0,N) range 0 N minj = i minj i for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
         j range(i, N) range i N if A[j][0] < A[minj][0]:
                 minj = j
         A[j][0] < A[minj][0] A[j][0] [j] A j 0 A[minj][0] [minj] A minj 0 minj = j minj j if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp i != minj i minj tmp = A[i] tmp A[i] A i A[i] = A[minj] A[i] A i A[minj] A minj A[minj] = tmp A[minj] A minj tmp A A N N def StableCheck(A):
    tmp = [0,0]
    for t in A:
        if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
        tmp = t
    return True StableCheck tmp = [0,0] tmp [0,0] 0 0 for t in A:
        if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
        tmp = t
     t A if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
         tmp[1] > t[1] tmp[1] tmp 1 t[1] t 1 if(tmp[0] == t[0]):
                return False
         tmp[0] == t[0] tmp[0] tmp 0 t[0] t 0 return False False tmp = t tmp t return True True A A BubbleSort(IN1,N) BubbleSort IN1 N InsertionSort(IN2,N) InsertionSort IN2 N for i in range(N - 1):
    print(IN1[i][2],end=' ') i range(N - 1) range N - 1 N 1 print(IN1[i][2],end=' ') print IN1[i][2] [i] IN1 i 2 end=' ' end ' ' print(IN1[N - 1][2]) print IN1[N - 1][2] [N - 1] IN1 N - 1 N 1 2 if(StableCheck(IN1)):print("Stable")
else:print("Not stable") StableCheck(IN1) StableCheck IN1 for i in range(N - 1):
    print(IN2[i][2],end=' ') i range(N - 1) range N - 1 N 1 print(IN2[i][2],end=' ') print IN2[i][2] [i] IN2 i 2 end=' ' end ' ' print(IN2[N - 1][2]) print IN2[N - 1][2] [N - 1] IN2 N - 1 N 1 2 if(StableCheck(IN2)):print("Stable")
else:print("Not stable") StableCheck(IN2) StableCheck IN2 i+=1 1 i def InsertionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp def InsertionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp InsertionSort def BubbleSort(A,N):
    for i in range(N - 1):
        for j in range(N - 1, i,-1):
            if A[j][0] < A[j - 1][0]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp def BubbleSort(A,N):
    for i in range(N - 1):
        for j in range(N - 1, i,-1):
            if A[j][0] < A[j - 1][0]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp BubbleSort def StableCheck(A):
    tmp = [0,0]
    for t in A:
        if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
        tmp = t
    return True def StableCheck(A):
    tmp = [0,0]
    for t in A:
        if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
        tmp = t
    return True StableCheck i=0 0 i tmp = int(a.lstrip("SHCD")) int(a.lstrip("SHCD")) tmp N = int(input()) int(input()) N A = input() input() A IN1 = [None] * N [None] * N IN1 IN2 = [None] * N [None] * N IN2
#coding: UTF-8

N = int(input())
A = input()
#A = list(map(int, input().split()))
IN1 = [None] * N
IN2 = [None] * N
i=0


for a in A.split():
    tmp = int(a.lstrip("SHCD"))
    IN1[i] = [tmp, i, a]
    IN2[i] = [tmp, i, a]
    i+=1

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

def InsertionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i, N):
            if A[j][0] < A[minj][0]:
                 minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp

def StableCheck(A):
    tmp = [0,0]
    for t in A:
        if(tmp[1] > t[1]):
            if(tmp[0] == t[0]):
                return False
        tmp = t
    return True


BubbleSort(IN1,N)
InsertionSort(IN2,N)

for i in range(N - 1):
    print(IN1[i][2],end=' ')
print(IN1[N - 1][2])
if(StableCheck(IN1)):print("Stable")
else:print("Not stable")

for i in range(N - 1):
    print(IN2[i][2],end=' ')
print(IN2[N - 1][2])
if(StableCheck(IN2)):print("Stable")
else:print("Not stable")