def isStable(inlist, outlist):
	flag = True
	for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	return(flag)
N = int(input())
A = input().split()
B = A[:]
C = A[:]

flag = 1
counter = 0
while flag:
    flag = 0
    for i in reversed(range(1,N)):
        if int(C[i][1:]) < int(C[i-1][1:]):
            C[i], C[i-1] = C[i-1], C[i]
            counter += 1
            flag = 1
print(" ".join(map(str, C)))

if(isStable(A, C)):
	print("Stable")
else:
	print("Not stable")

counter=0
for i in range(N):
	Br = B[i:]
	Brr = [int(Br[j][1:]) for j in range(N-i)]
	num = Brr.index(min(Brr)) 
	if num != 0:
		B[i], B[(i+num)] = B[(i+num)], B[i]
		counter += 1
print(" ".join(map(str,B)))
if(isStable(A, B)):
	print("Stable")
else:
	print("Not stable") def isStable(inlist, outlist):
	flag = True
	for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	return(flag) isStable flag = True flag True for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	 i range(0, N) range 0 N for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		 j range(i+1, N) range i+1 i 1 N for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			 a range(0, N) range 0 N for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				 b range(a+1, N) range a+1 a 1 N if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				 int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a] int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] int(inlist[i][1:]) == int(inlist[j][1:]) int(inlist[i][1:]) int inlist[i][1:] [i] inlist i 1: 1 int(inlist[j][1:]) int inlist[j][1:] [j] inlist j 1: 1 inlist[i] == outlist[b] inlist[i] inlist i outlist[b] outlist b inlist[j] == outlist[a] inlist[j] inlist j outlist[a] outlist a flag = False flag False break continue break continue break continue break return(flag) flag inlist inlist outlist outlist N = int(input()) N int(input()) int input() input A = input().split() A input().split() ().split () input split B = A[:] B A[:] A : C = A[:] C A[:] A : flag = 1 flag 1 counter = 0 counter 0 while flag:
    flag = 0
    for i in reversed(range(1,N)):
        if int(C[i][1:]) < int(C[i-1][1:]):
            C[i], C[i-1] = C[i-1], C[i]
            counter += 1
            flag = 1 flag flag = 0 flag 0 for i in reversed(range(1,N)):
        if int(C[i][1:]) < int(C[i-1][1:]):
            C[i], C[i-1] = C[i-1], C[i]
            counter += 1
            flag = 1 i reversed(range(1,N)) reversed range(1,N) range 1 N if int(C[i][1:]) < int(C[i-1][1:]):
            C[i], C[i-1] = C[i-1], C[i]
            counter += 1
            flag = 1 int(C[i][1:]) < int(C[i-1][1:]) int(C[i][1:]) int C[i][1:] [i] C i 1: 1 int(C[i-1][1:]) int C[i-1][1:] [i-1] C i-1 i 1 1: 1 C[i], C[i-1] = C[i-1], C[i] C[i] C i C[i-1] C i-1 i 1 C[i-1] C i-1 i 1 C[i] C i counter += 1 counter 1 flag = 1 flag 1 print(" ".join(map(str, C))) print " ".join(map(str, C)) " ".join " " join map(str, C) map str C if(isStable(A, C)):
	print("Stable")
else:
	print("Not stable") isStable(A, C) isStable A C print("Stable") print "Stable" print("Not stable") print "Not stable" counter=0 counter 0 for i in range(N):
	Br = B[i:]
	Brr = [int(Br[j][1:]) for j in range(N-i)]
	num = Brr.index(min(Brr)) 
	if num != 0:
		B[i], B[(i+num)] = B[(i+num)], B[i]
		counter += 1 i range(N) range N Br = B[i:] Br B[i:] B i: i int(Br[j][1:]) for j in range(N-i) for j in range(N-i) j range(N-i) range N-i N i for j in range(N-i) int(Br[j][1:]) int Br[j][1:] [j] Br j 1: 1 Brr = [int(Br[j][1:]) for j in range(N-i)] Brr [int(Br[j][1:]) for j in range(N-i)] num = Brr.index(min(Brr)) num Brr.index(min(Brr)) Brr.index Brr index min(Brr) min Brr if num != 0:
		B[i], B[(i+num)] = B[(i+num)], B[i]
		counter += 1 num != 0 num 0 B[i], B[(i+num)] = B[(i+num)], B[i] B[i] B i B[(i+num)] B i+num i num B[(i+num)] B i+num i num B[i] B i counter += 1 counter 1 print(" ".join(map(str,B))) print " ".join(map(str,B)) " ".join " " join map(str,B) map str B if(isStable(A, B)):
	print("Stable")
else:
	print("Not stable") isStable(A, B) isStable A B print("Stable") print "Stable" print("Not stable") print "Not stable" num = Brr.index(min(Brr)) Brr.index(min(Brr)) num B = A[:] A[:] B A = input().split() input().split() A flag = 1 1 flag Br = B[i:] B[i:] Br flag = 1 1 flag counter = 0 0 counter flag = 0 0 flag def isStable(inlist, outlist):
	flag = True
	for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	return(flag) def isStable(inlist, outlist):
	flag = True
	for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	return(flag) isStable counter=0 0 counter C = A[:] A[:] C counter += 1 1 counter Brr = [int(Br[j][1:]) for j in range(N-i)] [int(Br[j][1:]) for j in range(N-i)] Brr N = int(input()) int(input()) N counter += 1 1 counter
def isStable(inlist, outlist):
	flag = True
	for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	return(flag)
N = int(input())
A = input().split()
B = A[:]
C = A[:]

flag = 1
counter = 0
while flag:
    flag = 0
    for i in reversed(range(1,N)):
        if int(C[i][1:]) < int(C[i-1][1:]):
            C[i], C[i-1] = C[i-1], C[i]
            counter += 1
            flag = 1
print(" ".join(map(str, C)))

if(isStable(A, C)):
	print("Stable")
else:
	print("Not stable")

counter=0
for i in range(N):
	Br = B[i:]
	Brr = [int(Br[j][1:]) for j in range(N-i)]
	num = Brr.index(min(Brr)) 
	if num != 0:
		B[i], B[(i+num)] = B[(i+num)], B[i]
		counter += 1
print(" ".join(map(str,B)))
if(isStable(A, B)):
	print("Stable")
else:
	print("Not stable")