import copy

def BubbleSort(arr):
	n=len(arr)
	for i in range(n):
		for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	return arr

def SelectionSort(arr):
	n=len(arr)
	for i in range(n):
		minp=i
		for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		arr[minp],arr[i]=arr[i],arr[minp]
	return arr
  
def IsStable(basearr,resultarr):
  checkarr1=[[] for _ in range(14)]
  checkarr2=[[] for _ in range(14)]
  for i in range(len(basearr)):
    checkarr1[int(basearr[i][1])].append(basearr[i][0])
    checkarr2[int(resultarr[i][1])].append(resultarr[i][0])
  if checkarr1==checkarr2:
    print('Stable')
  else:
    print('Not stable')
  

n=int(input())
arr=list(map(str,input().split()))
bubble=BubbleSort(copy.deepcopy(arr))
selection=SelectionSort(copy.deepcopy(arr))
print(' '.join(map(str,bubble)))
IsStable(arr,bubble)
print(' '.join(map(str,selection)))
IsStable(arr,selection) import copy copy def BubbleSort(arr):
	n=len(arr)
	for i in range(n):
		for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	return arr BubbleSort n=len(arr) n len(arr) len arr for i in range(n):
		for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	 i range(n) range n for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	 j range(n-1,i,-1) range n-1 n 1 i -1 if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	 int(arr[j][1])<int(arr[j-1][1]) int(arr[j][1]) int arr[j][1] [j] arr j 1 int(arr[j-1][1]) int arr[j-1][1] [j-1] arr j-1 j 1 1 arr[j],arr[j-1]=arr[j-1],arr[j] arr[j] arr j arr[j-1] arr j-1 j 1 arr[j-1] arr j-1 j 1 arr[j] arr j return arr arr arr arr def SelectionSort(arr):
	n=len(arr)
	for i in range(n):
		minp=i
		for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		arr[minp],arr[i]=arr[i],arr[minp]
	return arr
   SelectionSort n=len(arr) n len(arr) len arr for i in range(n):
		minp=i
		for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		arr[minp],arr[i]=arr[i],arr[minp]
	 i range(n) range n minp=i minp i for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		 j range(i,n) range i n if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		 int(arr[j][1])<int(arr[minp][1]) int(arr[j][1]) int arr[j][1] [j] arr j 1 int(arr[minp][1]) int arr[minp][1] [minp] arr minp 1 minp=j minp j arr[minp],arr[i]=arr[i],arr[minp] arr[minp] arr minp arr[i] arr i arr[i] arr i arr[minp] arr minp return arr arr arr arr def IsStable(basearr,resultarr):
  checkarr1=[[] for _ in range(14)]
  checkarr2=[[] for _ in range(14)]
  for i in range(len(basearr)):
    checkarr1[int(basearr[i][1])].append(basearr[i][0])
    checkarr2[int(resultarr[i][1])].append(resultarr[i][0])
  if checkarr1==checkarr2:
    print('Stable')
  else:
    print('Not stable')
   IsStable [] for _ in range(14) for _ in range(14) _ range(14) range 14 for _ in range(14) [] checkarr1=[[] for _ in range(14)] checkarr1 [[] for _ in range(14)] [] for _ in range(14) for _ in range(14) _ range(14) range 14 for _ in range(14) [] checkarr2=[[] for _ in range(14)] checkarr2 [[] for _ in range(14)] for i in range(len(basearr)):
    checkarr1[int(basearr[i][1])].append(basearr[i][0])
    checkarr2[int(resultarr[i][1])].append(resultarr[i][0])
   i range(len(basearr)) range len(basearr) len basearr checkarr1[int(basearr[i][1])].append(basearr[i][0]) [int(basearr[i][1])].append [int(basearr[i][1])] checkarr1 int(basearr[i][1]) int basearr[i][1] [i] basearr i 1 append basearr[i][0] [i] basearr i 0 checkarr2[int(resultarr[i][1])].append(resultarr[i][0]) [int(resultarr[i][1])].append [int(resultarr[i][1])] checkarr2 int(resultarr[i][1]) int resultarr[i][1] [i] resultarr i 1 append resultarr[i][0] [i] resultarr i 0 if checkarr1==checkarr2:
    print('Stable')
  else:
    print('Not stable')
   checkarr1==checkarr2 checkarr1 checkarr2 print('Stable') print 'Stable' print('Not stable') print 'Not stable' basearr basearr resultarr resultarr 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 bubble=BubbleSort(copy.deepcopy(arr)) bubble BubbleSort(copy.deepcopy(arr)) BubbleSort copy.deepcopy(arr) copy.deepcopy copy deepcopy arr selection=SelectionSort(copy.deepcopy(arr)) selection SelectionSort(copy.deepcopy(arr)) SelectionSort copy.deepcopy(arr) copy.deepcopy copy deepcopy arr print(' '.join(map(str,bubble))) print ' '.join(map(str,bubble)) ' '.join ' ' join map(str,bubble) map str bubble IsStable(arr,bubble) IsStable arr bubble print(' '.join(map(str,selection))) print ' '.join(map(str,selection)) ' '.join ' ' join map(str,selection) map str selection IsStable(arr,selection) IsStable arr selection def IsStable(basearr,resultarr):
  checkarr1=[[] for _ in range(14)]
  checkarr2=[[] for _ in range(14)]
  for i in range(len(basearr)):
    checkarr1[int(basearr[i][1])].append(basearr[i][0])
    checkarr2[int(resultarr[i][1])].append(resultarr[i][0])
  if checkarr1==checkarr2:
    print('Stable')
  else:
    print('Not stable')
   def IsStable(basearr,resultarr):
  checkarr1=[[] for _ in range(14)]
  checkarr2=[[] for _ in range(14)]
  for i in range(len(basearr)):
    checkarr1[int(basearr[i][1])].append(basearr[i][0])
    checkarr2[int(resultarr[i][1])].append(resultarr[i][0])
  if checkarr1==checkarr2:
    print('Stable')
  else:
    print('Not stable')
   IsStable arr=list(map(str,input().split())) list(map(str,input().split())) arr def BubbleSort(arr):
	n=len(arr)
	for i in range(n):
		for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	return arr def BubbleSort(arr):
	n=len(arr)
	for i in range(n):
		for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	return arr BubbleSort selection=SelectionSort(copy.deepcopy(arr)) SelectionSort(copy.deepcopy(arr)) selection n=int(input()) int(input()) n def SelectionSort(arr):
	n=len(arr)
	for i in range(n):
		minp=i
		for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		arr[minp],arr[i]=arr[i],arr[minp]
	return arr
   def SelectionSort(arr):
	n=len(arr)
	for i in range(n):
		minp=i
		for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		arr[minp],arr[i]=arr[i],arr[minp]
	return arr
   SelectionSort bubble=BubbleSort(copy.deepcopy(arr)) BubbleSort(copy.deepcopy(arr)) bubble
import copy

def BubbleSort(arr):
	n=len(arr)
	for i in range(n):
		for j in range(n-1,i,-1):
			if int(arr[j][1])<int(arr[j-1][1]):
				arr[j],arr[j-1]=arr[j-1],arr[j]
	return arr

def SelectionSort(arr):
	n=len(arr)
	for i in range(n):
		minp=i
		for j in range(i,n):
			if int(arr[j][1])<int(arr[minp][1]):
				minp=j
		arr[minp],arr[i]=arr[i],arr[minp]
	return arr
  
def IsStable(basearr,resultarr):
  checkarr1=[[] for _ in range(14)]
  checkarr2=[[] for _ in range(14)]
  for i in range(len(basearr)):
    checkarr1[int(basearr[i][1])].append(basearr[i][0])
    checkarr2[int(resultarr[i][1])].append(resultarr[i][0])
  if checkarr1==checkarr2:
    print('Stable')
  else:
    print('Not stable')
  

n=int(input())
arr=list(map(str,input().split()))
bubble=BubbleSort(copy.deepcopy(arr))
selection=SelectionSort(copy.deepcopy(arr))
print(' '.join(map(str,bubble)))
IsStable(arr,bubble)
print(' '.join(map(str,selection)))
IsStable(arr,selection)
