import copy
n=int(input())
num=input().split()
numa=copy.copy(num)
numb=copy.copy(num)

#buble
for i in range(0,n):
	a=0
	for j in range(n-1,i,-1):
		if numa[j][1:]<numa[j-1][1:]:
			a=numa[j]
			numa[j]=numa[j-1]
			numa[j-1]=a
print(' '.join(list(map(str,numa))))
print('Stable')

#select
for i in range(0,n):
	minj=i
	b=0
	for j in range(i,n):
		if numb[j][1:]<numb[minj][1:]:
			minj=j
	b=numb[minj]
	numb[minj]=numb[i]
	numb[i]=b
print(' '.join(list(map(str,numb))))
if numb==numa:
	print('Stable')
else:
	print('Not stable')
		
 import copy copy n=int(input()) n int(input()) int input() input num=input().split() num input().split() ().split () input split numa=copy.copy(num) numa copy.copy(num) copy.copy copy copy num numb=copy.copy(num) numb copy.copy(num) copy.copy copy copy num for i in range(0,n):
	a=0
	for j in range(n-1,i,-1):
		if numa[j][1:]<numa[j-1][1:]:
			a=numa[j]
			numa[j]=numa[j-1]
			numa[j-1]=a i range(0,n) range 0 n a=0 a 0 for j in range(n-1,i,-1):
		if numa[j][1:]<numa[j-1][1:]:
			a=numa[j]
			numa[j]=numa[j-1]
			numa[j-1]=a j range(n-1,i,-1) range n-1 n 1 i -1 if numa[j][1:]<numa[j-1][1:]:
			a=numa[j]
			numa[j]=numa[j-1]
			numa[j-1]=a numa[j][1:]<numa[j-1][1:] numa[j][1:] [j] numa j 1: 1 numa[j-1][1:] [j-1] numa j-1 j 1 1: 1 a=numa[j] a numa[j] numa j numa[j]=numa[j-1] numa[j] numa j numa[j-1] numa j-1 j 1 numa[j-1]=a numa[j-1] numa j-1 j 1 a print(' '.join(list(map(str,numa)))) print ' '.join(list(map(str,numa))) ' '.join ' ' join list(map(str,numa)) list map(str,numa) map str numa print('Stable') print 'Stable' for i in range(0,n):
	minj=i
	b=0
	for j in range(i,n):
		if numb[j][1:]<numb[minj][1:]:
			minj=j
	b=numb[minj]
	numb[minj]=numb[i]
	numb[i]=b i range(0,n) range 0 n minj=i minj i b=0 b 0 for j in range(i,n):
		if numb[j][1:]<numb[minj][1:]:
			minj=j
	 j range(i,n) range i n if numb[j][1:]<numb[minj][1:]:
			minj=j
	 numb[j][1:]<numb[minj][1:] numb[j][1:] [j] numb j 1: 1 numb[minj][1:] [minj] numb minj 1: 1 minj=j minj j b=numb[minj] b numb[minj] numb minj numb[minj]=numb[i] numb[minj] numb minj numb[i] numb i numb[i]=b numb[i] numb i b print(' '.join(list(map(str,numb)))) print ' '.join(list(map(str,numb))) ' '.join ' ' join list(map(str,numb)) list map(str,numb) map str numb if numb==numa:
	print('Stable')
else:
	print('Not stable')
		 numb==numa numb numa print('Stable') print 'Stable' print('Not stable') print 'Not stable' numa=copy.copy(num) copy.copy(num) numa minj=j j minj numb=copy.copy(num) copy.copy(num) numb b=0 0 b minj=i i minj b=numb[minj] numb[minj] b num=input().split() input().split() num a=0 0 a n=int(input()) int(input()) n a=numa[j] numa[j] a
import copy
n=int(input())
num=input().split()
numa=copy.copy(num)
numb=copy.copy(num)

#buble
for i in range(0,n):
	a=0
	for j in range(n-1,i,-1):
		if numa[j][1:]<numa[j-1][1:]:
			a=numa[j]
			numa[j]=numa[j-1]
			numa[j-1]=a
print(' '.join(list(map(str,numa))))
print('Stable')

#select
for i in range(0,n):
	minj=i
	b=0
	for j in range(i,n):
		if numb[j][1:]<numb[minj][1:]:
			minj=j
	b=numb[minj]
	numb[minj]=numb[i]
	numb[i]=b
print(' '.join(list(map(str,numb))))
if numb==numa:
	print('Stable')
else:
	print('Not stable')
		

