length = int(input())
targ = [n for n in input().split(' ')]
selecttarg = targ[:]
#bubbleflag = 0
for l in range(length):
    for init in range(l):
        if targ[l - init][1] < targ[l - init - 1][1]:
            disp = targ[l-init]
            targ[l-init] = targ[l-init-1]
            targ[l-init-1] = disp
print(' '.join([str(n) for n in targ]))

print("Stable")

selectflag = 0
for l in range(length):
    value = l
    samevalue = l
    for init in range(l+1,length):
        if selecttarg[value][1] > selecttarg[init][1]:
            value = init
        elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
    if samevalue != l and value != l and value > samevalue:
        selectflag = 1
    disp = selecttarg[l]
    selecttarg[l] = selecttarg[value]
    selecttarg[value] = disp
print(' '.join([str(n) for n in selecttarg]))
if selectflag == 0:
    print("Stable")
else:
    print("Not stable") length = int(input()) length int(input()) int input() input n for n in input().split(' ') for n in input().split(' ') n input().split(' ') ().split () input split ' ' for n in input().split(' ') n targ = [n for n in input().split(' ')] targ [n for n in input().split(' ')] selecttarg = targ[:] selecttarg targ[:] targ : for l in range(length):
    for init in range(l):
        if targ[l - init][1] < targ[l - init - 1][1]:
            disp = targ[l-init]
            targ[l-init] = targ[l-init-1]
            targ[l-init-1] = disp l range(length) range length for init in range(l):
        if targ[l - init][1] < targ[l - init - 1][1]:
            disp = targ[l-init]
            targ[l-init] = targ[l-init-1]
            targ[l-init-1] = disp init range(l) range l if targ[l - init][1] < targ[l - init - 1][1]:
            disp = targ[l-init]
            targ[l-init] = targ[l-init-1]
            targ[l-init-1] = disp targ[l - init][1] < targ[l - init - 1][1] targ[l - init][1] [l - init] targ l - init l init 1 targ[l - init - 1][1] [l - init - 1] targ l - init - 1 l - init l init 1 1 disp = targ[l-init] disp targ[l-init] targ l-init l init targ[l-init] = targ[l-init-1] targ[l-init] targ l-init l init targ[l-init-1] targ l-init-1 l-init l init 1 targ[l-init-1] = disp targ[l-init-1] targ l-init-1 l-init l init 1 disp str(n) for n in targ for n in targ n targ for n in targ str(n) str n print(' '.join([str(n) for n in targ])) print ' '.join([str(n) for n in targ]) ' '.join ' ' join [str(n) for n in targ] print("Stable") print "Stable" selectflag = 0 selectflag 0 for l in range(length):
    value = l
    samevalue = l
    for init in range(l+1,length):
        if selecttarg[value][1] > selecttarg[init][1]:
            value = init
        elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
    if samevalue != l and value != l and value > samevalue:
        selectflag = 1
    disp = selecttarg[l]
    selecttarg[l] = selecttarg[value]
    selecttarg[value] = disp l range(length) range length value = l value l samevalue = l samevalue l for init in range(l+1,length):
        if selecttarg[value][1] > selecttarg[init][1]:
            value = init
        elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
     init range(l+1,length) range l+1 l 1 length if selecttarg[value][1] > selecttarg[init][1]:
            value = init
        elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
     selecttarg[value][1] > selecttarg[init][1] selecttarg[value][1] [value] selecttarg value 1 selecttarg[init][1] [init] selecttarg init 1 value = init value init elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
     selectflag != 1 and selecttarg[l][1] == selecttarg[init][1] selectflag != 1 selectflag 1 selecttarg[l][1] == selecttarg[init][1] selecttarg[l][1] [l] selecttarg l 1 selecttarg[init][1] [init] selecttarg init 1 samevalue = init samevalue init if samevalue != l and value != l and value > samevalue:
        selectflag = 1
     samevalue != l and value != l and value > samevalue samevalue != l and value != l samevalue != l samevalue l value != l value l value > samevalue value samevalue selectflag = 1 selectflag 1 disp = selecttarg[l] disp selecttarg[l] selecttarg l selecttarg[l] = selecttarg[value] selecttarg[l] selecttarg l selecttarg[value] selecttarg value selecttarg[value] = disp selecttarg[value] selecttarg value disp str(n) for n in selecttarg for n in selecttarg n selecttarg for n in selecttarg str(n) str n print(' '.join([str(n) for n in selecttarg])) print ' '.join([str(n) for n in selecttarg]) ' '.join ' ' join [str(n) for n in selecttarg] if selectflag == 0:
    print("Stable")
else:
    print("Not stable") selectflag == 0 selectflag 0 print("Stable") print "Stable" print("Not stable") print "Not stable" samevalue = init init samevalue value = l l value value = init init value samevalue = l l samevalue disp = targ[l-init] targ[l-init] disp selecttarg = targ[:] targ[:] selecttarg selectflag = 1 1 selectflag disp = selecttarg[l] selecttarg[l] disp selectflag = 0 0 selectflag length = int(input()) int(input()) length targ = [n for n in input().split(' ')] [n for n in input().split(' ')] targ
length = int(input())
targ = [n for n in input().split(' ')]
selecttarg = targ[:]
#bubbleflag = 0
for l in range(length):
    for init in range(l):
        if targ[l - init][1] < targ[l - init - 1][1]:
            disp = targ[l-init]
            targ[l-init] = targ[l-init-1]
            targ[l-init-1] = disp
print(' '.join([str(n) for n in targ]))

print("Stable")

selectflag = 0
for l in range(length):
    value = l
    samevalue = l
    for init in range(l+1,length):
        if selecttarg[value][1] > selecttarg[init][1]:
            value = init
        elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
    if samevalue != l and value != l and value > samevalue:
        selectflag = 1
    disp = selecttarg[l]
    selecttarg[l] = selecttarg[value]
    selecttarg[value] = disp
print(' '.join([str(n) for n in selecttarg]))
if selectflag == 0:
    print("Stable")
else:
    print("Not stable")