#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re

def embedded_numbers(str):
	re_digits = re.compile(r'(\d+)')
	pieces = re_digits.split(str)
	pieces[1] = map(int, pieces[1])
	return pieces[1]

def selectionSort(Arry):
	for i in range(len(Arry)):
		minj = i
		for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		Arry[i],Arry[minj] = Arry[minj], Arry[i]

	return Arry

def bubbleSort(Arry):
	for i in range(len(Arry)):
		for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	return Arry

def judge_satble(origin, sortedCards):
	if sorted(origin, key=embedded_numbers) == sortedCards:
		print "Stable"
	else:
		print "Not stable"

def main():
	
	N = int(raw_input())
	Cards = raw_input().split()
	s_cards = list(Cards)
	b_cards = list(Cards)
	
	bubble_sortedCards = bubbleSort(b_cards)
	print " ".join(bubble_sortedCards)
	judge_satble(Cards, bubble_sortedCards)

	select_sortedCards = selectionSort(s_cards)
	print " ".join(select_sortedCards)
	judge_satble(Cards, select_sortedCards)


#def test():
	#if  1 > embedded_numbers("s8"):
		#print "ok"


	
if __name__ == '__main__':
	main()
	#test() import re re def embedded_numbers(str):
	re_digits = re.compile(r'(\d+)')
	pieces = re_digits.split(str)
	pieces[1] = map(int, pieces[1])
	return pieces[1] embedded_numbers re_digits = re.compile(r'(\d+)') re_digits re.compile(r'(\d+)') re.compile re compile r'(\d+)' pieces = re_digits.split(str) pieces re_digits.split(str) re_digits.split re_digits split str pieces[1] = map(int, pieces[1]) pieces[1] pieces 1 map(int, pieces[1]) map int pieces[1] pieces 1 return pieces[1] pieces[1] pieces 1 str str def selectionSort(Arry):
	for i in range(len(Arry)):
		minj = i
		for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		Arry[i],Arry[minj] = Arry[minj], Arry[i]

	return Arry selectionSort for i in range(len(Arry)):
		minj = i
		for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		Arry[i],Arry[minj] = Arry[minj], Arry[i]

	 i range(len(Arry)) range len(Arry) len Arry minj = i minj i for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		 j range(i,len(Arry)) range i len(Arry) len Arry if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		 embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]) embedded_numbers(Arry[j]) embedded_numbers Arry[j] Arry j embedded_numbers(Arry[minj]) embedded_numbers Arry[minj] Arry minj minj = j minj j Arry[i],Arry[minj] = Arry[minj], Arry[i] Arry[i] Arry i Arry[minj] Arry minj Arry[minj] Arry minj Arry[i] Arry i return Arry Arry Arry Arry def bubbleSort(Arry):
	for i in range(len(Arry)):
		for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	return Arry bubbleSort for i in range(len(Arry)):
		for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	 i range(len(Arry)) range len(Arry) len Arry for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	 j range(len(Arry) - 1, i, -1) range len(Arry) - 1 len(Arry) len Arry 1 i -1 if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	 embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]) embedded_numbers(Arry[j-1]) embedded_numbers Arry[j-1] Arry j-1 j 1 embedded_numbers(Arry[j]) embedded_numbers Arry[j] Arry j Arry[j-1], Arry[j] = Arry[j], Arry[j - 1] Arry[j-1] Arry j-1 j 1 Arry[j] Arry j Arry[j] Arry j Arry[j - 1] Arry j - 1 j 1 return Arry Arry Arry Arry def judge_satble(origin, sortedCards):
	if sorted(origin, key=embedded_numbers) == sortedCards:
		print "Stable"
	else:
		print "Not stable" judge_satble if sorted(origin, key=embedded_numbers) == sortedCards:
		print "Stable"
	else:
		print "Not stable" sorted(origin, key=embedded_numbers) == sortedCards sorted(origin, key=embedded_numbers) sorted origin key=embedded_numbers key embedded_numbers sortedCards print print origin origin sortedCards sortedCards def main():
	
	N = int(raw_input())
	Cards = raw_input().split()
	s_cards = list(Cards)
	b_cards = list(Cards)
	
	bubble_sortedCards = bubbleSort(b_cards)
	print " ".join(bubble_sortedCards)
	judge_satble(Cards, bubble_sortedCards)

	select_sortedCards = selectionSort(s_cards)
	print " ".join(select_sortedCards)
	judge_satble(Cards, select_sortedCards)


#def test():
	#if  1 > embedded_numbers("s8"):
		#print "ok"


	 main N = int(raw_input()) N int(raw_input()) int raw_input() raw_input Cards = raw_input().split() Cards raw_input().split() ().split () raw_input split s_cards = list(Cards) s_cards list(Cards) list Cards b_cards = list(Cards) b_cards list(Cards) list Cards bubble_sortedCards = bubbleSort(b_cards) bubble_sortedCards bubbleSort(b_cards) bubbleSort b_cards print " ".join(bubble_sortedCards) " ".join " " join bubble_sortedCards judge_satble(Cards, bubble_sortedCards) judge_satble Cards bubble_sortedCards select_sortedCards = selectionSort(s_cards) select_sortedCards selectionSort(s_cards) selectionSort s_cards print " ".join(select_sortedCards) " ".join " " join select_sortedCards judge_satble(Cards, select_sortedCards) judge_satble Cards select_sortedCards if __name__ == '__main__':
	main()
	#test() __name__ == '__main__' __name__ '__main__' main() main def main():
	
	N = int(raw_input())
	Cards = raw_input().split()
	s_cards = list(Cards)
	b_cards = list(Cards)
	
	bubble_sortedCards = bubbleSort(b_cards)
	print " ".join(bubble_sortedCards)
	judge_satble(Cards, bubble_sortedCards)

	select_sortedCards = selectionSort(s_cards)
	print " ".join(select_sortedCards)
	judge_satble(Cards, select_sortedCards)


#def test():
	#if  1 > embedded_numbers("s8"):
		#print "ok"


	 def main():
	
	N = int(raw_input())
	Cards = raw_input().split()
	s_cards = list(Cards)
	b_cards = list(Cards)
	
	bubble_sortedCards = bubbleSort(b_cards)
	print " ".join(bubble_sortedCards)
	judge_satble(Cards, bubble_sortedCards)

	select_sortedCards = selectionSort(s_cards)
	print " ".join(select_sortedCards)
	judge_satble(Cards, select_sortedCards)


#def test():
	#if  1 > embedded_numbers("s8"):
		#print "ok"


	 main def bubbleSort(Arry):
	for i in range(len(Arry)):
		for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	return Arry def bubbleSort(Arry):
	for i in range(len(Arry)):
		for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	return Arry bubbleSort def selectionSort(Arry):
	for i in range(len(Arry)):
		minj = i
		for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		Arry[i],Arry[minj] = Arry[minj], Arry[i]

	return Arry def selectionSort(Arry):
	for i in range(len(Arry)):
		minj = i
		for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		Arry[i],Arry[minj] = Arry[minj], Arry[i]

	return Arry selectionSort def embedded_numbers(str):
	re_digits = re.compile(r'(\d+)')
	pieces = re_digits.split(str)
	pieces[1] = map(int, pieces[1])
	return pieces[1] def embedded_numbers(str):
	re_digits = re.compile(r'(\d+)')
	pieces = re_digits.split(str)
	pieces[1] = map(int, pieces[1])
	return pieces[1] embedded_numbers def judge_satble(origin, sortedCards):
	if sorted(origin, key=embedded_numbers) == sortedCards:
		print "Stable"
	else:
		print "Not stable" def judge_satble(origin, sortedCards):
	if sorted(origin, key=embedded_numbers) == sortedCards:
		print "Stable"
	else:
		print "Not stable" judge_satble
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re

def embedded_numbers(str):
	re_digits = re.compile(r'(\d+)')
	pieces = re_digits.split(str)
	pieces[1] = map(int, pieces[1])
	return pieces[1]

def selectionSort(Arry):
	for i in range(len(Arry)):
		minj = i
		for j in range(i,len(Arry)):
			if embedded_numbers(Arry[j]) < embedded_numbers(Arry[minj]):
				minj = j
		Arry[i],Arry[minj] = Arry[minj], Arry[i]

	return Arry

def bubbleSort(Arry):
	for i in range(len(Arry)):
		for j in range(len(Arry) - 1, i, -1):
			if embedded_numbers(Arry[j-1]) > embedded_numbers(Arry[j]):
				Arry[j-1], Arry[j] = Arry[j], Arry[j - 1]
	
	return Arry

def judge_satble(origin, sortedCards):
	if sorted(origin, key=embedded_numbers) == sortedCards:
		print "Stable"
	else:
		print "Not stable"

def main():
	
	N = int(raw_input())
	Cards = raw_input().split()
	s_cards = list(Cards)
	b_cards = list(Cards)
	
	bubble_sortedCards = bubbleSort(b_cards)
	print " ".join(bubble_sortedCards)
	judge_satble(Cards, bubble_sortedCards)

	select_sortedCards = selectionSort(s_cards)
	print " ".join(select_sortedCards)
	judge_satble(Cards, select_sortedCards)


#def test():
	#if  1 > embedded_numbers("s8"):
		#print "ok"


	
if __name__ == '__main__':
	main()
	#test()