N = int(input())
array = list(input().split())
array2 = array[:]
array3 = array[:]

def bubble_sort(array, N):
	flag = 1
	i = 0
	while flag:
		flag = 0 
		j = N-1
		while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		i += 1


def selection_sort(array, n):
	for i in range(n):
		minij = i 
		for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		array[i], array[minij] = array[minij], array[i]

def is_stable(Input, output, n):
	for i in range(n):
		for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	return True 

bubble_sort(array, N)
print(' '.join(array))
print('Stable')
selection_sort(array2,N)
print(' '.join(array2))
if is_stable(array3, array2, N):
	print('Stable')
else:
	print('Not stable')




 N = int(input()) N int(input()) int input() input array = list(input().split()) array list(input().split()) list input().split() ().split () input split array2 = array[:] array2 array[:] array : array3 = array[:] array3 array[:] array : def bubble_sort(array, N):
	flag = 1
	i = 0
	while flag:
		flag = 0 
		j = N-1
		while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		i += 1 bubble_sort flag = 1 flag 1 i = 0 i 0 while flag:
		flag = 0 
		j = N-1
		while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		i += 1 flag flag = 0 flag 0 j = N-1 j N-1 N 1 while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		 j > i j i if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			 array[j][1] < array[j-1][1] array[j][1] [j] array j 1 array[j-1][1] [j-1] array j-1 j 1 1 array[j], array[j-1] = array[j-1], array[j] array[j] array j array[j-1] array j-1 j 1 array[j-1] array j-1 j 1 array[j] array j j -= 1 j 1 flag = 1 flag 1 i += 1 i 1 array array N N def selection_sort(array, n):
	for i in range(n):
		minij = i 
		for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		array[i], array[minij] = array[minij], array[i] selection_sort for i in range(n):
		minij = i 
		for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		array[i], array[minij] = array[minij], array[i] i range(n) range n minij = i minij i for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		 j range(i, n) range i n if array[j][1] < array[minij][1]:
			    minij = j 
		 array[j][1] < array[minij][1] array[j][1] [j] array j 1 array[minij][1] [minij] array minij 1 minij = j minij j array[i], array[minij] = array[minij], array[i] array[i] array i array[minij] array minij array[minij] array minij array[i] array i array array n n def is_stable(Input, output, n):
	for i in range(n):
		for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	return True  is_stable for i in range(n):
		for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	 i range(n) range n for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	 j range(i+1, n) range i+1 i 1 n for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	 a range(n) range n for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	 b range(a+1, n) range a+1 a 1 n if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	 Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a] Input[i][1] == Input[j][1] and Input[i] == output[b] Input[i][1] == Input[j][1] Input[i][1] [i] Input i 1 Input[j][1] [j] Input j 1 Input[i] == output[b] Input[i] Input i output[b] output b Input[j] == output[a] Input[j] Input j output[a] output a return False False return True True Input Input output output n n bubble_sort(array, N) bubble_sort array N print(' '.join(array)) print ' '.join(array) ' '.join ' ' join array print('Stable') print 'Stable' selection_sort(array2,N) selection_sort array2 N print(' '.join(array2)) print ' '.join(array2) ' '.join ' ' join array2 if is_stable(array3, array2, N):
	print('Stable')
else:
	print('Not stable') is_stable(array3, array2, N) is_stable array3 array2 N print('Stable') print 'Stable' print('Not stable') print 'Not stable' array = list(input().split()) list(input().split()) array array2 = array[:] array[:] array2 array3 = array[:] array[:] array3 def selection_sort(array, n):
	for i in range(n):
		minij = i 
		for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		array[i], array[minij] = array[minij], array[i] def selection_sort(array, n):
	for i in range(n):
		minij = i 
		for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		array[i], array[minij] = array[minij], array[i] selection_sort N = int(input()) int(input()) N def bubble_sort(array, N):
	flag = 1
	i = 0
	while flag:
		flag = 0 
		j = N-1
		while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		i += 1 def bubble_sort(array, N):
	flag = 1
	i = 0
	while flag:
		flag = 0 
		j = N-1
		while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		i += 1 bubble_sort def is_stable(Input, output, n):
	for i in range(n):
		for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	return True  def is_stable(Input, output, n):
	for i in range(n):
		for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	return True  is_stable
N = int(input())
array = list(input().split())
array2 = array[:]
array3 = array[:]

def bubble_sort(array, N):
	flag = 1
	i = 0
	while flag:
		flag = 0 
		j = N-1
		while j > i:
			if array[j][1] < array[j-1][1]:
				array[j], array[j-1] = array[j-1], array[j]
			j -= 1
			flag = 1
		i += 1


def selection_sort(array, n):
	for i in range(n):
		minij = i 
		for j in range(i, n):
			if array[j][1] < array[minij][1]:
			    minij = j 
		array[i], array[minij] = array[minij], array[i]

def is_stable(Input, output, n):
	for i in range(n):
		for j in range(i+1, n):
			for a in range(n):
				for b in range(a+1, n):
					if Input[i][1] == Input[j][1] and Input[i] == output[b] and Input[j] == output[a]:
						return False
	return True 

bubble_sort(array, N)
print(' '.join(array))
print('Stable')
selection_sort(array2,N)
print(' '.join(array2))
if is_stable(array3, array2, N):
	print('Stable')
else:
	print('Not stable')





