
numbers = []
n = int(raw_input())

S = raw_input()

b = S.split(" ")
s = S.split(" ")

for i in range(n):
    for j in  range(n - 1, i, -1):
        if int(b[j][-1]) < int(b[j - 1][-1]):
        	b[j], b[j - 1] = b[j - 1], b[j]
print ' '.join(b)
print "Stable"

for i in range(n):
	minj = i
	for j in range(i, n):
		if int(s[j][-1]) < int(s[minj][-1]):
			minj = j
	s[i], s[minj] = s[minj], s[i]

print ' '.join(s)
flag = 0
for i in range(n):
	if b[i] != s[i]:
		flag = 1
if flag:
	print "Not stable"
else:
	print "Stable" numbers = [] numbers [] n = int(raw_input()) n int(raw_input()) int raw_input() raw_input S = raw_input() S raw_input() raw_input b = S.split(" ") b S.split(" ") S.split S split " " s = S.split(" ") s S.split(" ") S.split S split " " for i in range(n):
    for j in  range(n - 1, i, -1):
        if int(b[j][-1]) < int(b[j - 1][-1]):
        	b[j], b[j - 1] = b[j - 1], b[j] i range(n) range n for j in  range(n - 1, i, -1):
        if int(b[j][-1]) < int(b[j - 1][-1]):
        	b[j], b[j - 1] = b[j - 1], b[j] j range(n - 1, i, -1) range n - 1 n 1 i -1 if int(b[j][-1]) < int(b[j - 1][-1]):
        	b[j], b[j - 1] = b[j - 1], b[j] int(b[j][-1]) < int(b[j - 1][-1]) int(b[j][-1]) int b[j][-1] [j] b j -1 int(b[j - 1][-1]) int b[j - 1][-1] [j - 1] b j - 1 j 1 -1 b[j], b[j - 1] = b[j - 1], b[j] b[j] b j b[j - 1] b j - 1 j 1 b[j - 1] b j - 1 j 1 b[j] b j print ' '.join(b) ' '.join ' ' join b print for i in range(n):
	minj = i
	for j in range(i, n):
		if int(s[j][-1]) < int(s[minj][-1]):
			minj = j
	s[i], s[minj] = s[minj], s[i] i range(n) range n minj = i minj i for j in range(i, n):
		if int(s[j][-1]) < int(s[minj][-1]):
			minj = j
	 j range(i, n) range i n if int(s[j][-1]) < int(s[minj][-1]):
			minj = j
	 int(s[j][-1]) < int(s[minj][-1]) int(s[j][-1]) int s[j][-1] [j] s j -1 int(s[minj][-1]) int s[minj][-1] [minj] s minj -1 minj = j minj j s[i], s[minj] = s[minj], s[i] s[i] s i s[minj] s minj s[minj] s minj s[i] s i print ' '.join(s) ' '.join ' ' join s flag = 0 flag 0 for i in range(n):
	if b[i] != s[i]:
		flag = 1 i range(n) range n if b[i] != s[i]:
		flag = 1 b[i] != s[i] b[i] b i s[i] s i flag = 1 flag 1 if flag:
	print "Not stable"
else:
	print "Stable" flag print print minj = i i minj s = S.split(" ") S.split(" ") s n = int(raw_input()) int(raw_input()) n b = S.split(" ") S.split(" ") b minj = j j minj S = raw_input() raw_input() S flag = 1 1 flag flag = 0 0 flag numbers = [] [] numbers

numbers = []
n = int(raw_input())

S = raw_input()

b = S.split(" ")
s = S.split(" ")

for i in range(n):
    for j in  range(n - 1, i, -1):
        if int(b[j][-1]) < int(b[j - 1][-1]):
        	b[j], b[j - 1] = b[j - 1], b[j]
print ' '.join(b)
print "Stable"

for i in range(n):
	minj = i
	for j in range(i, n):
		if int(s[j][-1]) < int(s[minj][-1]):
			minj = j
	s[i], s[minj] = s[minj], s[i]

print ' '.join(s)
flag = 0
for i in range(n):
	if b[i] != s[i]:
		flag = 1
if flag:
	print "Not stable"
else:
	print "Stable"