def bubble_sort(A, n):
	flag = 1
	i = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	return A

def selection_sort(A, n):
	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	return A

def is_stable(A, B, n):
	for i in range(0, n):
		for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	return True

def print_stable(flag):
	if flag:
		print('Stable')
	else:
		print('Not stable')

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	A2 = A[:]

	B = bubble_sort(A, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n))

	B = selection_sort(A2, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n)) def bubble_sort(A, n):
	flag = 1
	i = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	return A bubble_sort flag = 1 flag 1 i = 0 i 0 while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	 flag flag = 0 flag 0 for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		 j range(n-1, i, -1) range n-1 n 1 i -1 if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		 int(A[j][1]) < int(A[j-1][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[j-1][1]) int A[j-1][1] [j-1] A j-1 j 1 1 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 flag = 1 flag 1 i += 1 i 1 return A A A A n n def selection_sort(A, n):
	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	return A selection_sort for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	 i range(n-1) range n-1 n 1 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[i], A[minj] = A[minj], A[i]

	 i != minj i minj A[i], A[minj] = A[minj], A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i return A A A A n n def is_stable(A, B, n):
	for i in range(0, n):
		for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	return True is_stable for i in range(0, n):
		for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	 i range(0, n) range 0 n for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	 j range(i+1, n) range i+1 i 1 n for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	 a range(0, n) range 0 n for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	 b range(a+1, n) range a+1 a 1 n if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	 int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a] int(A[i][1]) == int(A[j][1]) and A[i] == B[b] int(A[i][1]) == int(A[j][1]) int(A[i][1]) int A[i][1] [i] A i 1 int(A[j][1]) int A[j][1] [j] A j 1 A[i] == B[b] A[i] A i B[b] B b A[j] == B[a] A[j] A j B[a] B a return False False return True True A A B B n n def print_stable(flag):
	if flag:
		print('Stable')
	else:
		print('Not stable') print_stable if flag:
		print('Stable')
	else:
		print('Not stable') flag print('Stable') print 'Stable' print('Not stable') print 'Not stable' flag flag if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	A2 = A[:]

	B = bubble_sort(A, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n))

	B = selection_sort(A2, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n)) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input A = list(input().split()) A list(input().split()) list input().split() ().split () input split A2 = A[:] A2 A[:] A : B = bubble_sort(A, n) B bubble_sort(A, n) bubble_sort A n print(' '.join(B)) print ' '.join(B) ' '.join ' ' join B print_stable(is_stable(A, B, n)) print_stable is_stable(A, B, n) is_stable A B n B = selection_sort(A2, n) B selection_sort(A2, n) selection_sort A2 n print(' '.join(B)) print ' '.join(B) ' '.join ' ' join B print_stable(is_stable(A, B, n)) print_stable is_stable(A, B, n) is_stable A B n A = list(input().split()) list(input().split()) A def print_stable(flag):
	if flag:
		print('Stable')
	else:
		print('Not stable') def print_stable(flag):
	if flag:
		print('Stable')
	else:
		print('Not stable') print_stable B = bubble_sort(A, n) bubble_sort(A, n) B def is_stable(A, B, n):
	for i in range(0, n):
		for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

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

	return True is_stable def bubble_sort(A, n):
	flag = 1
	i = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	return A def bubble_sort(A, n):
	flag = 1
	i = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	return A bubble_sort def selection_sort(A, n):
	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	return A def selection_sort(A, n):
	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	return A selection_sort B = selection_sort(A2, n) selection_sort(A2, n) B A2 = A[:] A[:] A2 n = int(input()) int(input()) n
def bubble_sort(A, n):
	flag = 1
	i = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	return A

def selection_sort(A, n):
	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	return A

def is_stable(A, B, n):
	for i in range(0, n):
		for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	return True

def print_stable(flag):
	if flag:
		print('Stable')
	else:
		print('Not stable')

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	A2 = A[:]

	B = bubble_sort(A, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n))

	B = selection_sort(A2, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n))