import sys

class Card:
	def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	def __str__(self):
		return self.card

def print_cards(arr_print, arr_compare):
	n = len(arr_print)
	same = True
	for i in range(n):
		if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		sys.stdout.write(str(arr_print[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	print()
	return same

def swap(arr, i, j):
	temp = arr[i]
	arr[i] = arr[j]
	arr[j] = temp

def bubble_sort(arr):
	n = len(arr)
	for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1)

def selection_sort(arr):
	n = len(arr)
	for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj)

n = int(input())
arr = list(map(str, input().split()))
cards1 = [None] * n
cards2 = [None] * n
for i in range(n):
	cards1[i] = Card(arr[i])
	cards2[i] = Card(arr[i])

bubble_sort(cards1)
selection_sort(cards2)

print_cards(cards1, None)
print('Stable')

stable = print_cards(cards2, cards1)
if stable == True:
	print('Stable')
else:
	print('Not stable')
 import sys sys class Card:
	def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	def __str__(self):
		return self.card Card def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	 __init__ self.card = card self.card self card card self.mark = card[0] self.mark self mark card[0] card 0 self.value = int(card[1]) self.value self value int(card[1]) int card[1] card 1 self self card card def __str__(self):
		return self.card __str__ return self.card self.card self card self self def print_cards(arr_print, arr_compare):
	n = len(arr_print)
	same = True
	for i in range(n):
		if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		sys.stdout.write(str(arr_print[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	print()
	return same print_cards n = len(arr_print) n len(arr_print) len arr_print same = True same True for i in range(n):
		if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		sys.stdout.write(str(arr_print[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	 i range(n) range n if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		 arr_compare != None and arr_print[i].card != arr_compare[i].card arr_compare != None arr_compare None arr_print[i].card != arr_compare[i].card arr_print[i].card [i] arr_print i card arr_compare[i].card [i] arr_compare i card sys.stdout.write(str(arr_print[i])) sys.stdout.write sys.stdout sys stdout write str(arr_print[i]) str arr_print[i] arr_print i if i != n - 1:
			sys.stdout.write(' ')
	 i != n - 1 i n - 1 n 1 sys.stdout.write(' ') sys.stdout.write sys.stdout sys stdout write ' ' print() print return same same arr_print arr_print arr_compare arr_compare def swap(arr, i, j):
	temp = arr[i]
	arr[i] = arr[j]
	arr[j] = temp swap temp = arr[i] temp arr[i] arr i arr[i] = arr[j] arr[i] arr i arr[j] arr j arr[j] = temp arr[j] arr j temp arr arr i i j j def bubble_sort(arr):
	n = len(arr)
	for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1) bubble_sort n = len(arr) n len(arr) len arr for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1) i range(0, n) range 0 n for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1) j range(n - 1, i, -1) range n - 1 n 1 i -1 if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1) arr[j].value < arr[j - 1].value arr[j].value [j] arr j value arr[j - 1].value [j - 1] arr j - 1 j 1 value swap(arr, j, j - 1) swap arr j j - 1 j 1 arr arr def selection_sort(arr):
	n = len(arr)
	for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj) selection_sort n = len(arr) n len(arr) len arr for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj) i range(n) range n minj = i minj i for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		 j range(i, n) range i n if arr[j].value < arr[minj].value:
				minj = j
		 arr[j].value < arr[minj].value arr[j].value [j] arr j value arr[minj].value [minj] arr minj value minj = j minj j if minj != i:
			swap(arr, i, minj) minj != i minj i swap(arr, i, minj) swap arr i minj arr arr n = int(input()) n int(input()) int input() input arr = list(map(str, input().split())) arr list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split cards1 = [None] * n cards1 [None] * n [None] None n cards2 = [None] * n cards2 [None] * n [None] None n for i in range(n):
	cards1[i] = Card(arr[i])
	cards2[i] = Card(arr[i]) i range(n) range n cards1[i] = Card(arr[i]) cards1[i] cards1 i Card(arr[i]) Card arr[i] arr i cards2[i] = Card(arr[i]) cards2[i] cards2 i Card(arr[i]) Card arr[i] arr i bubble_sort(cards1) bubble_sort cards1 selection_sort(cards2) selection_sort cards2 print_cards(cards1, None) print_cards cards1 None print('Stable') print 'Stable' stable = print_cards(cards2, cards1) stable print_cards(cards2, cards1) print_cards cards2 cards1 if stable == True:
	print('Stable')
else:
	print('Not stable') stable == True stable True print('Stable') print 'Stable' print('Not stable') print 'Not stable' def print_cards(arr_print, arr_compare):
	n = len(arr_print)
	same = True
	for i in range(n):
		if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		sys.stdout.write(str(arr_print[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	print()
	return same def print_cards(arr_print, arr_compare):
	n = len(arr_print)
	same = True
	for i in range(n):
		if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		sys.stdout.write(str(arr_print[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	print()
	return same print_cards arr = list(map(str, input().split())) list(map(str, input().split())) arr class Card:
	def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	def __str__(self):
		return self.card class Card:
	def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	def __str__(self):
		return self.card Card cards1 = [None] * n [None] * n cards1 def bubble_sort(arr):
	n = len(arr)
	for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1) def bubble_sort(arr):
	n = len(arr)
	for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1) bubble_sort cards2 = [None] * n [None] * n cards2 def selection_sort(arr):
	n = len(arr)
	for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj) def selection_sort(arr):
	n = len(arr)
	for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj) selection_sort n = int(input()) int(input()) n def swap(arr, i, j):
	temp = arr[i]
	arr[i] = arr[j]
	arr[j] = temp def swap(arr, i, j):
	temp = arr[i]
	arr[i] = arr[j]
	arr[j] = temp swap stable = print_cards(cards2, cards1) print_cards(cards2, cards1) stable
import sys

class Card:
	def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	def __str__(self):
		return self.card

def print_cards(arr_print, arr_compare):
	n = len(arr_print)
	same = True
	for i in range(n):
		if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
		sys.stdout.write(str(arr_print[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	print()
	return same

def swap(arr, i, j):
	temp = arr[i]
	arr[i] = arr[j]
	arr[j] = temp

def bubble_sort(arr):
	n = len(arr)
	for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1)

def selection_sort(arr):
	n = len(arr)
	for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj)

n = int(input())
arr = list(map(str, input().split()))
cards1 = [None] * n
cards2 = [None] * n
for i in range(n):
	cards1[i] = Card(arr[i])
	cards2[i] = Card(arr[i])

bubble_sort(cards1)
selection_sort(cards2)

print_cards(cards1, None)
print('Stable')

stable = print_cards(cards2, cards1)
if stable == True:
	print('Stable')
else:
	print('Not stable')

