n = int(input())
a = list(map(str,input().split()))

data1 = a[:]
data2 = a[:]

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

	return(data)

def selection_sort(data):
	for i in range(len(data)):
		minj = i
		for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		data[i],data[minj] = data[minj],data[i]

	return(data)
data1 = bubble_sort(data1)
data2 = selection_sort(data2)
print(*data1)
print("Stable")
print(*data2)
print("Stable" if data1 == data2 else "Not stable")
 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 data1 = a[:] data1 a[:] a : data2 = a[:] data2 a[:] a : def bubble_sort(data):
	for i in range(len(data)):
		for j in range(len(data)-1,i,-1):
			if(data[j][1] < data[j-1][1]):
				data[j],data[j-1] = data[j-1],data[j]

	return(data) bubble_sort for i in range(len(data)):
		for j in range(len(data)-1,i,-1):
			if(data[j][1] < data[j-1][1]):
				data[j],data[j-1] = data[j-1],data[j]

	 i range(len(data)) range len(data) len data for j in range(len(data)-1,i,-1):
			if(data[j][1] < data[j-1][1]):
				data[j],data[j-1] = data[j-1],data[j]

	 j range(len(data)-1,i,-1) range len(data)-1 len(data) len data 1 i -1 if(data[j][1] < data[j-1][1]):
				data[j],data[j-1] = data[j-1],data[j]

	 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 return(data) data data data def selection_sort(data):
	for i in range(len(data)):
		minj = i
		for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		data[i],data[minj] = data[minj],data[i]

	return(data) selection_sort for i in range(len(data)):
		minj = i
		for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		data[i],data[minj] = data[minj],data[i]

	 i range(len(data)) range len(data) len data minj = i minj i for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		 j range(i,len(data)) range i len(data) len data if(data[j][1] < data[minj][1]):
				minj = j

		 data[j][1] < data[minj][1] data[j][1] [j] data j 1 data[minj][1] [minj] data minj 1 minj = j minj j data[i],data[minj] = data[minj],data[i] data[i] data i data[minj] data minj data[minj] data minj data[i] data i return(data) data data data data1 = bubble_sort(data1) data1 bubble_sort(data1) bubble_sort data1 data2 = selection_sort(data2) data2 selection_sort(data2) selection_sort data2 print(*data1) print *data1 data1 print("Stable") print "Stable" print(*data2) print *data2 data2 print("Stable" if data1 == data2 else "Not stable") print "Stable" if data1 == data2 else "Not stable" data1 == data2 data1 data2 "Stable" "Not stable" data2 = a[:] a[:] data2 data2 = selection_sort(data2) selection_sort(data2) data2 def selection_sort(data):
	for i in range(len(data)):
		minj = i
		for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		data[i],data[minj] = data[minj],data[i]

	return(data) def selection_sort(data):
	for i in range(len(data)):
		minj = i
		for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		data[i],data[minj] = data[minj],data[i]

	return(data) selection_sort data1 = a[:] a[:] data1 data1 = bubble_sort(data1) bubble_sort(data1) data1 n = int(input()) int(input()) n a = list(map(str,input().split())) list(map(str,input().split())) a def bubble_sort(data):
	for i in range(len(data)):
		for j in range(len(data)-1,i,-1):
			if(data[j][1] < data[j-1][1]):
				data[j],data[j-1] = data[j-1],data[j]

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

	return(data) bubble_sort
n = int(input())
a = list(map(str,input().split()))

data1 = a[:]
data2 = a[:]

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

	return(data)

def selection_sort(data):
	for i in range(len(data)):
		minj = i
		for j in range(i,len(data)):
			if(data[j][1] < data[minj][1]):
				minj = j

		data[i],data[minj] = data[minj],data[i]

	return(data)
data1 = bubble_sort(data1)
data2 = selection_sort(data2)
print(*data1)
print("Stable")
print(*data2)
print("Stable" if data1 == data2 else "Not stable")

