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_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()

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

def bubble_sort(arr, n):
	swap_count = 0
	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)
				swap_count += 1
	return swap_count

def selection_sort(arr, n):
	stable = True
	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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			swap(arr, i, minj)
	return stable

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])

swap_count = bubble_sort(cards1, n)
stable = selection_sort(cards2, n)

print_arr(cards1)
print('Stable')
print_arr(cards2)
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_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print() print_arr for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	 i range(len(arr)) range len(arr) len arr sys.stdout.write(str(arr[i])) sys.stdout.write sys.stdout sys stdout write str(arr[i]) str arr[i] arr i if i != len(arr) - 1:
			sys.stdout.write(' ')
	 i != len(arr) - 1 i len(arr) - 1 len(arr) len arr 1 sys.stdout.write(' ') sys.stdout.write sys.stdout sys stdout write ' ' print() print arr arr 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):
	swap_count = 0
	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)
				swap_count += 1
	return swap_count bubble_sort swap_count = 0 swap_count 0 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)
				swap_count += 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)
				swap_count += 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)
				swap_count += 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 swap_count += 1 swap_count 1 return swap_count swap_count arr arr n n def selection_sort(arr, n):
	stable = True
	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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			swap(arr, i, minj)
	return stable selection_sort stable = True stable True 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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			swap(arr, i, minj)
	 minj != i minj i for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			 k range(i + 1, minj) range i + 1 i 1 minj if arr[k].value == arr[i].value: stable = False
			 arr[k].value == arr[i].value arr[k].value [k] arr k value arr[i].value [i] arr i value swap(arr, i, minj) swap arr i minj return stable stable arr arr n n 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 swap_count = bubble_sort(cards1, n) swap_count bubble_sort(cards1, n) bubble_sort cards1 n stable = selection_sort(cards2, n) stable selection_sort(cards2, n) selection_sort cards2 n print_arr(cards1) print_arr cards1 print('Stable') print 'Stable' print_arr(cards2) print_arr cards2 if stable == True:
	print('Stable')
else:
	print('Not stable') stable == True stable True print('Stable') print 'Stable' print('Not stable') print 'Not stable' cards1 = [None] * n [None] * n cards1 stable = selection_sort(cards2, n) selection_sort(cards2, n) stable def bubble_sort(arr, n):
	swap_count = 0
	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)
				swap_count += 1
	return swap_count def bubble_sort(arr, n):
	swap_count = 0
	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)
				swap_count += 1
	return swap_count bubble_sort n = int(input()) int(input()) n swap_count = bubble_sort(cards1, n) bubble_sort(cards1, n) swap_count arr = list(map(str, input().split())) list(map(str, input().split())) arr def selection_sort(arr, n):
	stable = True
	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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			swap(arr, i, minj)
	return stable def selection_sort(arr, n):
	stable = True
	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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			swap(arr, i, minj)
	return stable selection_sort 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 def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print() def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print() print_arr 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 cards2 = [None] * n [None] * n cards2
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_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()

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

def bubble_sort(arr, n):
	swap_count = 0
	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)
				swap_count += 1
	return swap_count

def selection_sort(arr, n):
	stable = True
	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:
			for k in range(i + 1, minj):
				if arr[k].value == arr[i].value: stable = False
			swap(arr, i, minj)
	return stable

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])

swap_count = bubble_sort(cards1, n)
stable = selection_sort(cards2, n)

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