import copy

n=int(input())
s=input().split(' ')
s1=[]
s2=[]
s1=copy.deepcopy(s)
s2=copy.deepcopy(s)

def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b)

def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b)

s1=Bubble_Sort(n,s1)
s2=Selection_Sort(n,s2)

print(' '.join(s1))
print('Stable')
print(' '.join(s2))
if s1==s2:
	print('Stable')
else:
	print('Not stable') import copy copy n=int(input()) n int(input()) int input() input s=input().split(' ') s input().split(' ') ().split () input split ' ' s1=[] s1 [] s2=[] s2 [] s1=copy.deepcopy(s) s1 copy.deepcopy(s) copy.deepcopy copy deepcopy s s2=copy.deepcopy(s) s2 copy.deepcopy(s) copy.deepcopy copy deepcopy s def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b) Bubble_Sort m=0 m 0 flag=1 flag 1 while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	 flag flag=0 flag 0 for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	 i range(1,n) range 1 n j=n-i j n-i n i if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	 int(s1[j][1])<int(s1[j-1][1]) int(s1[j][1]) int s1[j][1] [j] s1 j 1 int(s1[j-1][1]) int s1[j-1][1] [j-1] s1 j-1 j 1 1 a=s1[j] a s1[j] s1 j s1[j]=s1[j-1] s1[j] s1 j s1[j-1] s1 j-1 j 1 s1[j-1]=a s1[j-1] s1 j-1 j 1 a m+=1 m 1 flag=1 flag 1 b=s1 b s1 return(b) b n n s1 s1 def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b) Selection_Sort m=0 m 0 for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	 i range(n) range n minj=i minj i for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		 j range(i,n) range i n if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		 int(s2[j][1])<int(s2[minj][1]) int(s2[j][1]) int s2[j][1] [j] s2 j 1 int(s2[minj][1]) int s2[minj][1] [minj] s2 minj 1 minj=j minj j if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	 i!=minj i minj a=s2[minj] a s2[minj] s2 minj s2[minj]=s2[i] s2[minj] s2 minj s2[i] s2 i s2[i]=a s2[i] s2 i a m+=1 m 1 b=s2 b s2 return(b) b n n s2 s2 s1=Bubble_Sort(n,s1) s1 Bubble_Sort(n,s1) Bubble_Sort n s1 s2=Selection_Sort(n,s2) s2 Selection_Sort(n,s2) Selection_Sort n s2 print(' '.join(s1)) print ' '.join(s1) ' '.join ' ' join s1 print('Stable') print 'Stable' print(' '.join(s2)) print ' '.join(s2) ' '.join ' ' join s2 if s1==s2:
	print('Stable')
else:
	print('Not stable') s1==s2 s1 s2 print('Stable') print 'Stable' print('Not stable') print 'Not stable' s1=Bubble_Sort(n,s1) Bubble_Sort(n,s1) s1 s1=copy.deepcopy(s) copy.deepcopy(s) s1 n=int(input()) int(input()) n s=input().split(' ') input().split(' ') s s1=[] [] s1 s2=Selection_Sort(n,s2) Selection_Sort(n,s2) s2 s2=copy.deepcopy(s) copy.deepcopy(s) s2 s2=[] [] s2 def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b) def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b) Selection_Sort def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b) def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b) Bubble_Sort
import copy

n=int(input())
s=input().split(' ')
s1=[]
s2=[]
s1=copy.deepcopy(s)
s2=copy.deepcopy(s)

def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b)

def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b)

s1=Bubble_Sort(n,s1)
s2=Selection_Sort(n,s2)

print(' '.join(s1))
print('Stable')
print(' '.join(s2))
if s1==s2:
	print('Stable')
else:
	print('Not stable')
