N = int(input())
SI = list(input().split())
SB = SI.copy()

# bubble sort
for i in range(N):
	for j in range(N - 1, i, -1):
		if SB[j - 1][1] > SB[j][1]:
			x = SB[j - 1]
			SB[j - 1] = SB[j]
			SB[j] = x

# insertion sort
for i in range(N):
	ptr = i
	for j in range(i + 1, N):
		if SI[ptr][1] > SI[j][1]:
			ptr = j
	x = SI[i]
	SI[i] = SI[ptr]
	SI[ptr] = x

# print the answer!
for i in range(N):
	print(SB[i] + " " if i != N - 1 else str(SB[i]) + "\n", end='')
print("Stable")
for i in range(N):
	print(SI[i] + " " if i != N - 1 else str(SI[i]) + "\n", end='')
print("Stable" if SI == SB else "Not stable")
 N = int(input()) N int(input()) int input() input SI = list(input().split()) SI list(input().split()) list input().split() ().split () input split SB = SI.copy() SB SI.copy() SI.copy SI copy for i in range(N):
	for j in range(N - 1, i, -1):
		if SB[j - 1][1] > SB[j][1]:
			x = SB[j - 1]
			SB[j - 1] = SB[j]
			SB[j] = x

# insertion sort i range(N) range N for j in range(N - 1, i, -1):
		if SB[j - 1][1] > SB[j][1]:
			x = SB[j - 1]
			SB[j - 1] = SB[j]
			SB[j] = x

# insertion sort j range(N - 1, i, -1) range N - 1 N 1 i -1 if SB[j - 1][1] > SB[j][1]:
			x = SB[j - 1]
			SB[j - 1] = SB[j]
			SB[j] = x

# insertion sort SB[j - 1][1] > SB[j][1] SB[j - 1][1] [j - 1] SB j - 1 j 1 1 SB[j][1] [j] SB j 1 x = SB[j - 1] x SB[j - 1] SB j - 1 j 1 SB[j - 1] = SB[j] SB[j - 1] SB j - 1 j 1 SB[j] SB j SB[j] = x SB[j] SB j x for i in range(N):
	ptr = i
	for j in range(i + 1, N):
		if SI[ptr][1] > SI[j][1]:
			ptr = j
	x = SI[i]
	SI[i] = SI[ptr]
	SI[ptr] = x

# print the answer! i range(N) range N ptr = i ptr i for j in range(i + 1, N):
		if SI[ptr][1] > SI[j][1]:
			ptr = j
	 j range(i + 1, N) range i + 1 i 1 N if SI[ptr][1] > SI[j][1]:
			ptr = j
	 SI[ptr][1] > SI[j][1] SI[ptr][1] [ptr] SI ptr 1 SI[j][1] [j] SI j 1 ptr = j ptr j x = SI[i] x SI[i] SI i SI[i] = SI[ptr] SI[i] SI i SI[ptr] SI ptr SI[ptr] = x SI[ptr] SI ptr x for i in range(N):
	print(SB[i] + " " if i != N - 1 else str(SB[i]) + "\n", end='') i range(N) range N print(SB[i] + " " if i != N - 1 else str(SB[i]) + "\n", end='') print SB[i] + " " if i != N - 1 else str(SB[i]) + "\n" i != N - 1 i N - 1 N 1 SB[i] + " " SB[i] SB i " " str(SB[i]) + "\n" str(SB[i]) str SB[i] SB i "\n" end='' end '' print("Stable") print "Stable" for i in range(N):
	print(SI[i] + " " if i != N - 1 else str(SI[i]) + "\n", end='') i range(N) range N print(SI[i] + " " if i != N - 1 else str(SI[i]) + "\n", end='') print SI[i] + " " if i != N - 1 else str(SI[i]) + "\n" i != N - 1 i N - 1 N 1 SI[i] + " " SI[i] SI i " " str(SI[i]) + "\n" str(SI[i]) str SI[i] SI i "\n" end='' end '' print("Stable" if SI == SB else "Not stable") print "Stable" if SI == SB else "Not stable" SI == SB SI SB "Stable" "Not stable" N = int(input()) int(input()) N SB = SI.copy() SI.copy() SB ptr = j j ptr SI = list(input().split()) list(input().split()) SI ptr = i i ptr x = SB[j - 1] SB[j - 1] x x = SI[i] SI[i] x
N = int(input())
SI = list(input().split())
SB = SI.copy()

# bubble sort
for i in range(N):
	for j in range(N - 1, i, -1):
		if SB[j - 1][1] > SB[j][1]:
			x = SB[j - 1]
			SB[j - 1] = SB[j]
			SB[j] = x

# insertion sort
for i in range(N):
	ptr = i
	for j in range(i + 1, N):
		if SI[ptr][1] > SI[j][1]:
			ptr = j
	x = SI[i]
	SI[i] = SI[ptr]
	SI[ptr] = x

# print the answer!
for i in range(N):
	print(SB[i] + " " if i != N - 1 else str(SB[i]) + "\n", end='')
print("Stable")
for i in range(N):
	print(SI[i] + " " if i != N - 1 else str(SI[i]) + "\n", end='')
print("Stable" if SI == SB else "Not stable")

