n = int(input())
c = input().split()

cb = c[:]
for i in range(n):
	for j in range(n-1,i,-1):
		if cb[j][1] < cb[j-1][1]:
			cb[j-1],cb[j] = cb[j],cb[j-1]
print(*cb)
print('Stable')

cs = c[:]
for i in range(n):
	m = min(range(i,n), key=lambda j: cs[j][1])
	if i != m:
		cs[i],cs[m] = cs[m],cs[i]
print(*cs)
print('Stable' if cb == cs else 'Not stable') n = int(input()) n int(input()) int input() input c = input().split() c input().split() ().split () input split cb = c[:] cb c[:] c : for i in range(n):
	for j in range(n-1,i,-1):
		if cb[j][1] < cb[j-1][1]:
			cb[j-1],cb[j] = cb[j],cb[j-1] i range(n) range n for j in range(n-1,i,-1):
		if cb[j][1] < cb[j-1][1]:
			cb[j-1],cb[j] = cb[j],cb[j-1] j range(n-1,i,-1) range n-1 n 1 i -1 if cb[j][1] < cb[j-1][1]:
			cb[j-1],cb[j] = cb[j],cb[j-1] cb[j][1] < cb[j-1][1] cb[j][1] [j] cb j 1 cb[j-1][1] [j-1] cb j-1 j 1 1 cb[j-1],cb[j] = cb[j],cb[j-1] cb[j-1] cb j-1 j 1 cb[j] cb j cb[j] cb j cb[j-1] cb j-1 j 1 print(*cb) print *cb cb print('Stable') print 'Stable' cs = c[:] cs c[:] c : for i in range(n):
	m = min(range(i,n), key=lambda j: cs[j][1])
	if i != m:
		cs[i],cs[m] = cs[m],cs[i] i range(n) range n m = min(range(i,n), key=lambda j: cs[j][1]) m min(range(i,n), key=lambda j: cs[j][1]) min range(i,n) range i n key=lambda j: cs[j][1] key lambda j: cs[j][1] cs[j][1] [j] cs j 1 j if i != m:
		cs[i],cs[m] = cs[m],cs[i] i != m i m cs[i],cs[m] = cs[m],cs[i] cs[i] cs i cs[m] cs m cs[m] cs m cs[i] cs i print(*cs) print *cs cs print('Stable' if cb == cs else 'Not stable') print 'Stable' if cb == cs else 'Not stable' cb == cs cb cs 'Stable' 'Not stable' c = input().split() input().split() c n = int(input()) int(input()) n cb = c[:] c[:] cb cs = c[:] c[:] cs m = min(range(i,n), key=lambda j: cs[j][1]) min(range(i,n), key=lambda j: cs[j][1]) m
n = int(input())
c = input().split()

cb = c[:]
for i in range(n):
	for j in range(n-1,i,-1):
		if cb[j][1] < cb[j-1][1]:
			cb[j-1],cb[j] = cb[j],cb[j-1]
print(*cb)
print('Stable')

cs = c[:]
for i in range(n):
	m = min(range(i,n), key=lambda j: cs[j][1])
	if i != m:
		cs[i],cs[m] = cs[m],cs[i]
print(*cs)
print('Stable' if cb == cs else 'Not stable')
