def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))


N = ri()
a = rls()
bubble = a[:]

flag = True
while(flag):
    flag = False
    for i in range(1, N):
        if(bubble[-i][1] < bubble[-i-1][1]):
            hold = bubble[-i]
            bubble[-i] = bubble[-i-1]
            bubble[-i-1] = hold
            flag = True
pl(bubble)
print("Stable")  # ?????????Stable

selection = a[:]
for i in range(N):
    minj = i
    for j in range(i, N):
        if(selection[j][1] < selection[minj][1]):
            minj = j
    hold = selection[i]
    selection[i] = selection[minj]
    selection[minj] = hold

pl(selection)
print("Stable" if bubble == selection else "Not stable") def ri(): return int(input()) ri def rli(): return list(map(int, input().split())) rli def rls(): return list(map(str, input().split())) rls def pl(a): print(" ".join(list(map(str, a)))) pl a a N = ri() N ri() ri a = rls() a rls() rls bubble = a[:] bubble a[:] a : flag = True flag True while(flag):
    flag = False
    for i in range(1, N):
        if(bubble[-i][1] < bubble[-i-1][1]):
            hold = bubble[-i]
            bubble[-i] = bubble[-i-1]
            bubble[-i-1] = hold
            flag = True flag flag = False flag False for i in range(1, N):
        if(bubble[-i][1] < bubble[-i-1][1]):
            hold = bubble[-i]
            bubble[-i] = bubble[-i-1]
            bubble[-i-1] = hold
            flag = True i range(1, N) range 1 N if(bubble[-i][1] < bubble[-i-1][1]):
            hold = bubble[-i]
            bubble[-i] = bubble[-i-1]
            bubble[-i-1] = hold
            flag = True bubble[-i][1] < bubble[-i-1][1] bubble[-i][1] [-i] bubble -i i 1 bubble[-i-1][1] [-i-1] bubble -i-1 -i i 1 1 hold = bubble[-i] hold bubble[-i] bubble -i i bubble[-i] = bubble[-i-1] bubble[-i] bubble -i i bubble[-i-1] bubble -i-1 -i i 1 bubble[-i-1] = hold bubble[-i-1] bubble -i-1 -i i 1 hold flag = True flag True pl(bubble) pl bubble print("Stable") print "Stable" selection = a[:] selection a[:] a : for i in range(N):
    minj = i
    for j in range(i, N):
        if(selection[j][1] < selection[minj][1]):
            minj = j
    hold = selection[i]
    selection[i] = selection[minj]
    selection[minj] = hold i range(N) range N minj = i minj i for j in range(i, N):
        if(selection[j][1] < selection[minj][1]):
            minj = j
     j range(i, N) range i N if(selection[j][1] < selection[minj][1]):
            minj = j
     selection[j][1] < selection[minj][1] selection[j][1] [j] selection j 1 selection[minj][1] [minj] selection minj 1 minj = j minj j hold = selection[i] hold selection[i] selection i selection[i] = selection[minj] selection[i] selection i selection[minj] selection minj selection[minj] = hold selection[minj] selection minj hold pl(selection) pl selection print("Stable" if bubble == selection else "Not stable") print "Stable" if bubble == selection else "Not stable" bubble == selection bubble selection "Stable" "Not stable" minj = j j minj flag = True True flag N = ri() ri() N def ri(): return int(input()) def ri(): return int(input()) ri a = rls() rls() a selection = a[:] a[:] selection minj = i i minj hold = selection[i] selection[i] hold def pl(a): print(" ".join(list(map(str, a)))) def pl(a): print(" ".join(list(map(str, a)))) pl def rls(): return list(map(str, input().split())) def rls(): return list(map(str, input().split())) rls flag = False False flag def rli(): return list(map(int, input().split())) def rli(): return list(map(int, input().split())) rli flag = True True flag bubble = a[:] a[:] bubble hold = bubble[-i] bubble[-i] hold
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))


N = ri()
a = rls()
bubble = a[:]

flag = True
while(flag):
    flag = False
    for i in range(1, N):
        if(bubble[-i][1] < bubble[-i-1][1]):
            hold = bubble[-i]
            bubble[-i] = bubble[-i-1]
            bubble[-i-1] = hold
            flag = True
pl(bubble)
print("Stable")  # ?????????Stable

selection = a[:]
for i in range(N):
    minj = i
    for j in range(i, N):
        if(selection[j][1] < selection[minj][1]):
            minj = j
    hold = selection[i]
    selection[i] = selection[minj]
    selection[minj] = hold

pl(selection)
print("Stable" if bubble == selection else "Not stable")