N = int(input())
l = [list(i) for i in input().split()]

a = l.copy()
frag = 1
i = 0
while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
        frag = 1
    i += 1 
bubble_a = ["".join(a[i]) for i in range(N)]
print(" ".join(bubble_a))
print("Stable")

a = l.copy()
for i in range(N):
    minj = i
    for j in range(i,N):
        if a[j][1] < a[minj][1]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
selection_a = ["".join(a[i]) for i in range(N)]
print(" ".join(selection_a))

if bubble_a == selection_a:
    print("Stable")
else:
    print("Not stable") N = int(input()) N int(input()) int input() input list(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() list(i) list i l = [list(i) for i in input().split()] l [list(i) for i in input().split()] a = l.copy() a l.copy() l.copy l copy frag = 1 frag 1 i = 0 i 0 while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
        frag = 1
    i += 1  frag frag = 0 frag 0 for j in range(N-1,i,-1):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
        frag = 1
     j range(N-1,i,-1) range N-1 N 1 i -1 if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
         a[j][1] < a[j-1][1] a[j][1] [j] a j 1 a[j-1][1] [j-1] a j-1 j 1 1 a[j], a[j-1] = a[j-1], a[j] a[j] a j a[j-1] a j-1 j 1 a[j-1] a j-1 j 1 a[j] a j frag = 1 frag 1 i += 1 i 1 "".join(a[i]) for i in range(N) for i in range(N) i range(N) range N for i in range(N) "".join(a[i]) "".join "" join a[i] a i bubble_a = ["".join(a[i]) for i in range(N)] bubble_a ["".join(a[i]) for i in range(N)] print(" ".join(bubble_a)) print " ".join(bubble_a) " ".join " " join bubble_a print("Stable") print "Stable" a = l.copy() a l.copy() l.copy l copy for i in range(N):
    minj = i
    for j in range(i,N):
        if a[j][1] < a[minj][1]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i] i range(N) range N minj = i minj i for j in range(i,N):
        if a[j][1] < a[minj][1]:
            minj = j
     j range(i,N) range i N if a[j][1] < a[minj][1]:
            minj = j
     a[j][1] < a[minj][1] a[j][1] [j] a j 1 a[minj][1] [minj] a minj 1 minj = j minj j if i != minj:
        a[i], a[minj] = a[minj], a[i] i != minj i minj a[i], a[minj] = a[minj], a[i] a[i] a i a[minj] a minj a[minj] a minj a[i] a i "".join(a[i]) for i in range(N) for i in range(N) i range(N) range N for i in range(N) "".join(a[i]) "".join "" join a[i] a i selection_a = ["".join(a[i]) for i in range(N)] selection_a ["".join(a[i]) for i in range(N)] print(" ".join(selection_a)) print " ".join(selection_a) " ".join " " join selection_a if bubble_a == selection_a:
    print("Stable")
else:
    print("Not stable") bubble_a == selection_a bubble_a selection_a print("Stable") print "Stable" print("Not stable") print "Not stable" frag = 1 1 frag bubble_a = ["".join(a[i]) for i in range(N)] ["".join(a[i]) for i in range(N)] bubble_a a = l.copy() l.copy() a i = 0 0 i frag = 1 1 frag a = l.copy() l.copy() a frag = 0 0 frag minj = i i minj minj = j j minj selection_a = ["".join(a[i]) for i in range(N)] ["".join(a[i]) for i in range(N)] selection_a N = int(input()) int(input()) N l = [list(i) for i in input().split()] [list(i) for i in input().split()] l i += 1 1 i
N = int(input())
l = [list(i) for i in input().split()]

a = l.copy()
frag = 1
i = 0
while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
        frag = 1
    i += 1 
bubble_a = ["".join(a[i]) for i in range(N)]
print(" ".join(bubble_a))
print("Stable")

a = l.copy()
for i in range(N):
    minj = i
    for j in range(i,N):
        if a[j][1] < a[minj][1]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
selection_a = ["".join(a[i]) for i in range(N)]
print(" ".join(selection_a))

if bubble_a == selection_a:
    print("Stable")
else:
    print("Not stable")