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

def SelectionSort(C,n):
	for i in range(n):
		minj = i
		for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		C[i],C[minj] = C[minj],C[i]
	return C

def stable(C):
	new = []
	for i in range(1,10):
		Ci = [cc for cc in C if cc[1]==str(i)]
		new += Ci
	return new

n = int(input())
C = input().split()
x,y,z = C[:],C[:],C[:]
bubble = BubbleSort(x,n)
selection = SelectionSort(y,n)
sta = stable(z)

print(' '.join(bubble))
print({True:'Stable',False:'Not stable'}[sta==bubble])
print(' '.join(selection))
print({True:'Stable',False:'Not stable'}[sta==selection]) def BubbleSort(C,n):
	for i in range(n):
		for j in range(i+1,n)[::-1]:
			if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	return C BubbleSort for i in range(n):
		for j in range(i+1,n)[::-1]:
			if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	 i range(n) range n for j in range(i+1,n)[::-1]:
			if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	 j range(i+1,n)[::-1] (i+1,n) range i+1 i 1 n ::-1 -1 if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	 C[j][1] < C[j-1][1] C[j][1] [j] C j 1 C[j-1][1] [j-1] C j-1 j 1 1 C[j],C[j-1] = C[j-1],C[j] C[j] C j C[j-1] C j-1 j 1 C[j-1] C j-1 j 1 C[j] C j return C C C C n n def SelectionSort(C,n):
	for i in range(n):
		minj = i
		for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		C[i],C[minj] = C[minj],C[i]
	return C SelectionSort for i in range(n):
		minj = i
		for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		C[i],C[minj] = C[minj],C[i]
	 i range(n) range n minj = i minj i for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		 j range(i,n) range i n if C[j][1] < C[minj][1]:
				minj = j
		 C[j][1] < C[minj][1] C[j][1] [j] C j 1 C[minj][1] [minj] C minj 1 minj = j minj j C[i],C[minj] = C[minj],C[i] C[i] C i C[minj] C minj C[minj] C minj C[i] C i return C C C C n n def stable(C):
	new = []
	for i in range(1,10):
		Ci = [cc for cc in C if cc[1]==str(i)]
		new += Ci
	return new stable new = [] new [] for i in range(1,10):
		Ci = [cc for cc in C if cc[1]==str(i)]
		new += Ci
	 i range(1,10) range 1 10 cc for cc in C if cc[1]==str(i) for cc in C if cc[1]==str(i) cc C cc[1]==str(i) cc[1] cc 1 str(i) str i if cc[1]==str(i) cc Ci = [cc for cc in C if cc[1]==str(i)] Ci [cc for cc in C if cc[1]==str(i)] new += Ci new Ci return new new C C n = int(input()) n int(input()) int input() input C = input().split() C input().split() ().split () input split x,y,z = C[:],C[:],C[:] x C[:] C : y C[:] C : z C[:] C : bubble = BubbleSort(x,n) bubble BubbleSort(x,n) BubbleSort x n selection = SelectionSort(y,n) selection SelectionSort(y,n) SelectionSort y n sta = stable(z) sta stable(z) stable z print(' '.join(bubble)) print ' '.join(bubble) ' '.join ' ' join bubble print({True:'Stable',False:'Not stable'}[sta==bubble]) print {True:'Stable',False:'Not stable'}[sta==bubble] {True:'Stable',False:'Not stable'} True True 'Stable' False False 'Not stable' sta==bubble sta bubble print(' '.join(selection)) print ' '.join(selection) ' '.join ' ' join selection print({True:'Stable',False:'Not stable'}[sta==selection]) print {True:'Stable',False:'Not stable'}[sta==selection] {True:'Stable',False:'Not stable'} True True 'Stable' False False 'Not stable' sta==selection sta selection sta = stable(z) stable(z) sta bubble = BubbleSort(x,n) BubbleSort(x,n) bubble n = int(input()) int(input()) n y,z = C[:],C[:],C[:] C[:] y def stable(C):
	new = []
	for i in range(1,10):
		Ci = [cc for cc in C if cc[1]==str(i)]
		new += Ci
	return new def stable(C):
	new = []
	for i in range(1,10):
		Ci = [cc for cc in C if cc[1]==str(i)]
		new += Ci
	return new stable selection = SelectionSort(y,n) SelectionSort(y,n) selection z = C[:],C[:],C[:] C[:] z x,y,z = C[:],C[:],C[:] C[:] x def BubbleSort(C,n):
	for i in range(n):
		for j in range(i+1,n)[::-1]:
			if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	return C def BubbleSort(C,n):
	for i in range(n):
		for j in range(i+1,n)[::-1]:
			if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	return C BubbleSort def SelectionSort(C,n):
	for i in range(n):
		minj = i
		for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		C[i],C[minj] = C[minj],C[i]
	return C def SelectionSort(C,n):
	for i in range(n):
		minj = i
		for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		C[i],C[minj] = C[minj],C[i]
	return C SelectionSort C = input().split() input().split() C
def BubbleSort(C,n):
	for i in range(n):
		for j in range(i+1,n)[::-1]:
			if C[j][1] < C[j-1][1]:
				C[j],C[j-1] = C[j-1],C[j]
	return C

def SelectionSort(C,n):
	for i in range(n):
		minj = i
		for j in range(i,n):
			if C[j][1] < C[minj][1]:
				minj = j
		C[i],C[minj] = C[minj],C[i]
	return C

def stable(C):
	new = []
	for i in range(1,10):
		Ci = [cc for cc in C if cc[1]==str(i)]
		new += Ci
	return new

n = int(input())
C = input().split()
x,y,z = C[:],C[:],C[:]
bubble = BubbleSort(x,n)
selection = SelectionSort(y,n)
sta = stable(z)

print(' '.join(bubble))
print({True:'Stable',False:'Not stable'}[sta==bubble])
print(' '.join(selection))
print({True:'Stable',False:'Not stable'}[sta==selection])