num = int(input())
A = input().split(" ")
B = A.copy()

#bubble sort
for i in range(num):
	for j in range(num-1,i,-1):
		#英字ではなく、数字で比較する
		m1 = int(A[j][1:])
		m2 = int(A[j-1][1:])
		if m1 < m2:
			A[j],A[j-1] = A[j-1],A[j]

print(*A)
print("Stable")

#selection sort
for i in range(num):
	minv = i
	for j in range(i+1,num):
		m1 = int(B[minv][1:])
		m2 = int(B[j][1:])
		if m1 > m2:
			minv = j
	B[i],B[minv] = B[minv],B[i]

print(*B)
if A == B:
	print("Stable")
else:
	print("Not stable")

 num = int(input()) num int(input()) int input() input A = input().split(" ") A input().split(" ") ().split () input split " " B = A.copy() B A.copy() A.copy A copy for i in range(num):
	for j in range(num-1,i,-1):
		#英字ではなく、数字で比較する
		m1 = int(A[j][1:])
		m2 = int(A[j-1][1:])
		if m1 < m2:
			A[j],A[j-1] = A[j-1],A[j] i range(num) range num for j in range(num-1,i,-1):
		#英字ではなく、数字で比較する
		m1 = int(A[j][1:])
		m2 = int(A[j-1][1:])
		if m1 < m2:
			A[j],A[j-1] = A[j-1],A[j] j range(num-1,i,-1) range num-1 num 1 i -1 m1 = int(A[j][1:]) m1 int(A[j][1:]) int A[j][1:] [j] A j 1: 1 m2 = int(A[j-1][1:]) m2 int(A[j-1][1:]) int A[j-1][1:] [j-1] A j-1 j 1 1: 1 if m1 < m2:
			A[j],A[j-1] = A[j-1],A[j] m1 < m2 m1 m2 A[j],A[j-1] = A[j-1],A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j print(*A) print *A A print("Stable") print "Stable" for i in range(num):
	minv = i
	for j in range(i+1,num):
		m1 = int(B[minv][1:])
		m2 = int(B[j][1:])
		if m1 > m2:
			minv = j
	B[i],B[minv] = B[minv],B[i] i range(num) range num minv = i minv i for j in range(i+1,num):
		m1 = int(B[minv][1:])
		m2 = int(B[j][1:])
		if m1 > m2:
			minv = j
	 j range(i+1,num) range i+1 i 1 num m1 = int(B[minv][1:]) m1 int(B[minv][1:]) int B[minv][1:] [minv] B minv 1: 1 m2 = int(B[j][1:]) m2 int(B[j][1:]) int B[j][1:] [j] B j 1: 1 if m1 > m2:
			minv = j
	 m1 > m2 m1 m2 minv = j minv j B[i],B[minv] = B[minv],B[i] B[i] B i B[minv] B minv B[minv] B minv B[i] B i print(*B) print *B B if A == B:
	print("Stable")
else:
	print("Not stable") A == B A B print("Stable") print "Stable" print("Not stable") print "Not stable" minv = j j minv m2 = int(A[j-1][1:]) int(A[j-1][1:]) m2 A = input().split(" ") input().split(" ") A B = A.copy() A.copy() B m1 = int(B[minv][1:]) int(B[minv][1:]) m1 m2 = int(B[j][1:]) int(B[j][1:]) m2 minv = i i minv m1 = int(A[j][1:]) int(A[j][1:]) m1 num = int(input()) int(input()) num
num = int(input())
A = input().split(" ")
B = A.copy()

#bubble sort
for i in range(num):
	for j in range(num-1,i,-1):
		#英字ではなく、数字で比較する
		m1 = int(A[j][1:])
		m2 = int(A[j-1][1:])
		if m1 < m2:
			A[j],A[j-1] = A[j-1],A[j]

print(*A)
print("Stable")

#selection sort
for i in range(num):
	minv = i
	for j in range(i+1,num):
		m1 = int(B[minv][1:])
		m2 = int(B[j][1:])
		if m1 > m2:
			minv = j
	B[i],B[minv] = B[minv],B[i]

print(*B)
if A == B:
	print("Stable")
else:
	print("Not stable")


