class Sort():
	def __init__(self,n,cards):
		self.cards = cards
		self.n = n

	def bubble_sort(self):
		# bubble sort
		flag = 1
		while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	def select_sort(self):
		for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	def check_stable(self,origin):
		check_org = [["" for i in range(self.n)] for k in range(9)]
		check_sort = [["" for i in range(self.n)] for k in range(9)]
		for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		flag = 0
		for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	def print_card(self):
		for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i]))

if __name__ == '__main__':
	n = int(input())
	card = input().split()
	card2 = card.copy()
	card_origin = card.copy()
	
	bubble = Sort(n,card)
	bubble.bubble_sort()
	bubble.print_card()
	bubble.check_stable(card_origin)
	
	select = Sort(n,card2)
	select.select_sort()
	select.print_card()
	select.check_stable(card_origin) class Sort():
	def __init__(self,n,cards):
		self.cards = cards
		self.n = n

	def bubble_sort(self):
		# bubble sort
		flag = 1
		while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	def select_sort(self):
		for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	def check_stable(self,origin):
		check_org = [["" for i in range(self.n)] for k in range(9)]
		check_sort = [["" for i in range(self.n)] for k in range(9)]
		for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		flag = 0
		for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	def print_card(self):
		for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i])) Sort def __init__(self,n,cards):
		self.cards = cards
		self.n = n

	 __init__ self.cards = cards self.cards self cards cards self.n = n self.n self n n self self n n cards cards def bubble_sort(self):
		# bubble sort
		flag = 1
		while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	 bubble_sort flag = 1 flag 1 while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	 flag != 0 flag 0 flag = 0 flag 0 rev = list(range(1,self.n)) rev list(range(1,self.n)) list range(1,self.n) range 1 self.n self n rev.reverse() rev.reverse rev reverse for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	 j rev if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	 int(self.cards[j][1]) < int(self.cards[j-1][1]) int(self.cards[j][1]) int self.cards[j][1] self.cards[j] self.cards self cards j 1 int(self.cards[j-1][1]) int self.cards[j-1][1] self.cards[j-1] self.cards self cards j-1 j 1 1 self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j] self.cards[j] self.cards self cards j self.cards[j-1] self.cards self cards j-1 j 1 self.cards[j-1] self.cards self cards j-1 j 1 self.cards[j] self.cards self cards j flag = 1 flag 1 self self def select_sort(self):
		for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	 select_sort for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	 i range(self.n) range self.n self n mini = i mini i for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			 j range(i,self.n) range i self.n self n if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			 int(self.cards[j][1]) < int(self.cards[mini][1]) int(self.cards[j][1]) int self.cards[j][1] self.cards[j] self.cards self cards j 1 int(self.cards[mini][1]) int self.cards[mini][1] self.cards[mini] self.cards self cards mini 1 mini = j mini j if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	 i != mini i mini self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i] self.cards[i] self.cards self cards i self.cards[mini] self.cards self cards mini self.cards[mini] self.cards self cards mini self.cards[i] self.cards self cards i self self def check_stable(self,origin):
		check_org = [["" for i in range(self.n)] for k in range(9)]
		check_sort = [["" for i in range(self.n)] for k in range(9)]
		for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		flag = 0
		for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	 check_stable ["" for i in range(self.n)] for k in range(9) for k in range(9) k range(9) range 9 for k in range(9) ["" for i in range(self.n)] check_org = [["" for i in range(self.n)] for k in range(9)] check_org [["" for i in range(self.n)] for k in range(9)] ["" for i in range(self.n)] for k in range(9) for k in range(9) k range(9) range 9 for k in range(9) ["" for i in range(self.n)] check_sort = [["" for i in range(self.n)] for k in range(9)] check_sort [["" for i in range(self.n)] for k in range(9)] for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		 i range(self.n) range self.n self n check_org[int(origin[i][1])-1][i] = origin[i][0] check_org[int(origin[i][1])-1][i] [int(origin[i][1])-1] check_org int(origin[i][1])-1 int(origin[i][1]) int origin[i][1] [i] origin i 1 1 i origin[i][0] [i] origin i 0 check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0] check_sort[int(self.cards[i][1])-1][i] [int(self.cards[i][1])-1] check_sort int(self.cards[i][1])-1 int(self.cards[i][1]) int self.cards[i][1] self.cards[i] self.cards self cards i 1 1 i self.cards[i][0] self.cards[i] self.cards self cards i 0 flag = 0 flag 0 for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		 i range(9) range 9 if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		 "".join(check_org[i]) != "".join(check_sort[i]) "".join(check_org[i]) "".join "" join check_org[i] check_org i "".join(check_sort[i]) "".join "" join check_sort[i] check_sort i flag = 1 flag 1 break if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	 flag == 0 flag 0 print("Stable") print "Stable" print("Not stable") print "Not stable" self self origin origin def print_card(self):
		for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i])) print_card for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i])) i range(self.n) range self.n self n if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i])) i != self.n-1 i self.n-1 self.n self n 1 print("%s" % (self.cards[i]),end=" ") print "%s" % (self.cards[i]) "%s" self.cards[i] self.cards self cards i end=" " end " " print("%s" % (self.cards[i])) print "%s" % (self.cards[i]) "%s" self.cards[i] self.cards self cards i self self if __name__ == '__main__':
	n = int(input())
	card = input().split()
	card2 = card.copy()
	card_origin = card.copy()
	
	bubble = Sort(n,card)
	bubble.bubble_sort()
	bubble.print_card()
	bubble.check_stable(card_origin)
	
	select = Sort(n,card2)
	select.select_sort()
	select.print_card()
	select.check_stable(card_origin) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input card = input().split() card input().split() ().split () input split card2 = card.copy() card2 card.copy() card.copy card copy card_origin = card.copy() card_origin card.copy() card.copy card copy bubble = Sort(n,card) bubble Sort(n,card) Sort n card bubble.bubble_sort() bubble.bubble_sort bubble bubble_sort bubble.print_card() bubble.print_card bubble print_card bubble.check_stable(card_origin) bubble.check_stable bubble check_stable card_origin select = Sort(n,card2) select Sort(n,card2) Sort n card2 select.select_sort() select.select_sort select select_sort select.print_card() select.print_card select print_card select.check_stable(card_origin) select.check_stable select check_stable card_origin n = int(input()) int(input()) n bubble = Sort(n,card) Sort(n,card) bubble card2 = card.copy() card.copy() card2 card_origin = card.copy() card.copy() card_origin class Sort():
	def __init__(self,n,cards):
		self.cards = cards
		self.n = n

	def bubble_sort(self):
		# bubble sort
		flag = 1
		while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	def select_sort(self):
		for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	def check_stable(self,origin):
		check_org = [["" for i in range(self.n)] for k in range(9)]
		check_sort = [["" for i in range(self.n)] for k in range(9)]
		for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		flag = 0
		for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	def print_card(self):
		for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i])) class Sort():
	def __init__(self,n,cards):
		self.cards = cards
		self.n = n

	def bubble_sort(self):
		# bubble sort
		flag = 1
		while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	def select_sort(self):
		for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	def check_stable(self,origin):
		check_org = [["" for i in range(self.n)] for k in range(9)]
		check_sort = [["" for i in range(self.n)] for k in range(9)]
		for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		flag = 0
		for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	def print_card(self):
		for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i])) Sort card = input().split() input().split() card select = Sort(n,card2) Sort(n,card2) select
class Sort():
	def __init__(self,n,cards):
		self.cards = cards
		self.n = n

	def bubble_sort(self):
		# bubble sort
		flag = 1
		while flag != 0:
			flag = 0
			rev = list(range(1,self.n))
			rev.reverse()
			for j in rev:
				if int(self.cards[j][1]) < int(self.cards[j-1][1]):
					self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
					flag = 1

	def select_sort(self):
		for i in range(self.n):
			mini = i
			for j in range(i,self.n):
				if int(self.cards[j][1]) < int(self.cards[mini][1]):
					mini = j
			if i != mini:
				self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]

	def check_stable(self,origin):
		check_org = [["" for i in range(self.n)] for k in range(9)]
		check_sort = [["" for i in range(self.n)] for k in range(9)]
		for i in range(self.n):
			check_org[int(origin[i][1])-1][i] = origin[i][0]
			check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
		flag = 0
		for i in range(9):
			if "".join(check_org[i]) != "".join(check_sort[i]):
				flag = 1
				break

		if flag == 0:
			print("Stable")
		else:
			print("Not stable")

	def print_card(self):
		for i in range(self.n):
			if i != self.n-1:
				print("%s" % (self.cards[i]),end=" ")
			else:
				print("%s" % (self.cards[i]))

if __name__ == '__main__':
	n = int(input())
	card = input().split()
	card2 = card.copy()
	card_origin = card.copy()
	
	bubble = Sort(n,card)
	bubble.bubble_sort()
	bubble.print_card()
	bubble.check_stable(card_origin)
	
	select = Sort(n,card2)
	select.select_sort()
	select.print_card()
	select.check_stable(card_origin)
