class card:

    def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

    def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q


n = int(input())
a = list(map(card, input().split()))


b = a[:]
c = a[:]

for i in range(n):
    for j in range(n-1, i, -1):
        if b[j].v < b[j-1].v:
            b[j], b[j-1] = b[j-1],b[j]

print(" ".join(x.self_str() for x in b))

coua = ["" for i in range(10)]
coub = ["" for i in range(10)]
conb = ""
for i in range(n):
    for j in range(n):
        if i != j:
            if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
            if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c
if coua == coub:
     conb = "Stable"
else:
    conb = "Not stable"
print(conb)





for i in range(n):
    mini = i
    for j in range(i, n):
        if c[j].v < c[mini].v:
            mini = j
    c[mini], c[i] = c[i], c[mini]

print(" ".join(x.self_str() for x in c))

couc = ["" for i in range(10)]
conc = ""
for i in range(n):
    for j in range(n):
        if i != j:
            if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c
if coua == couc:
     conc = "Stable"
else:
    conc = "Not stable"

print(conc) class card:

    def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

    def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q card def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

     __init__ c = cv[0:1] c cv[0:1] cv 0:1 0 1 v = int(cv[1:2]) v int(cv[1:2]) int cv[1:2] cv 1:2 1 2 self.c = c self.c self c c self.v = v self.v self v v self self cv cv def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q self_str q = str(str(self.c) + str(self.v)) q str(str(self.c) + str(self.v)) str str(self.c) + str(self.v) str(self.c) str self.c self c str(self.v) str self.v self v return q q self self n = int(input()) n int(input()) int input() input a = list(map(card, input().split())) a list(map(card, input().split())) list map(card, input().split()) map card input().split() ().split () input split b = a[:] b a[:] a : c = a[:] c a[:] a : for i in range(n):
    for j in range(n-1, i, -1):
        if b[j].v < b[j-1].v:
            b[j], b[j-1] = b[j-1],b[j] i range(n) range n for j in range(n-1, i, -1):
        if b[j].v < b[j-1].v:
            b[j], b[j-1] = b[j-1],b[j] j range(n-1, i, -1) range n-1 n 1 i -1 if b[j].v < b[j-1].v:
            b[j], b[j-1] = b[j-1],b[j] b[j].v < b[j-1].v b[j].v [j] b j v b[j-1].v [j-1] b j-1 j 1 v b[j], b[j-1] = b[j-1],b[j] b[j] b j b[j-1] b j-1 j 1 b[j-1] b j-1 j 1 b[j] b j print(" ".join(x.self_str() for x in b)) print " ".join(x.self_str() for x in b) " ".join " " join x.self_str() x.self_str x self_str "" for i in range(10) for i in range(10) i range(10) range 10 for i in range(10) "" coua = ["" for i in range(10)] coua ["" for i in range(10)] "" for i in range(10) for i in range(10) i range(10) range 10 for i in range(10) "" coub = ["" for i in range(10)] coub ["" for i in range(10)] conb = "" conb "" for i in range(n):
    for j in range(n):
        if i != j:
            if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
            if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c i range(n) range n for j in range(n):
        if i != j:
            if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
            if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c j range(n) range n if i != j:
            if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
            if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c i != j i j if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
             a[i].v == a[j].v a[i].v [i] a i v a[j].v [j] a j v coua[a[i].v] += a[i].c coua[a[i].v] coua a[i].v [i] a i v a[i].c [i] a i c if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c b[i].v == b[j].v b[i].v [i] b i v b[j].v [j] b j v coub[b[i].v] += b[i].c coub[b[i].v] coub b[i].v [i] b i v b[i].c [i] b i c if coua == coub:
     conb = "Stable"
else:
    conb = "Not stable" coua == coub coua coub conb = "Stable" conb "Stable" conb = "Not stable" conb "Not stable" print(conb) print conb for i in range(n):
    mini = i
    for j in range(i, n):
        if c[j].v < c[mini].v:
            mini = j
    c[mini], c[i] = c[i], c[mini] i range(n) range n mini = i mini i for j in range(i, n):
        if c[j].v < c[mini].v:
            mini = j
     j range(i, n) range i n if c[j].v < c[mini].v:
            mini = j
     c[j].v < c[mini].v c[j].v [j] c j v c[mini].v [mini] c mini v mini = j mini j c[mini], c[i] = c[i], c[mini] c[mini] c mini c[i] c i c[i] c i c[mini] c mini print(" ".join(x.self_str() for x in c)) print " ".join(x.self_str() for x in c) " ".join " " join x.self_str() x.self_str x self_str "" for i in range(10) for i in range(10) i range(10) range 10 for i in range(10) "" couc = ["" for i in range(10)] couc ["" for i in range(10)] conc = "" conc "" for i in range(n):
    for j in range(n):
        if i != j:
            if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c i range(n) range n for j in range(n):
        if i != j:
            if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c j range(n) range n if i != j:
            if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c i != j i j if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c c[i].v == c[j].v c[i].v [i] c i v c[j].v [j] c j v couc[c[i].v] += c[i].c couc[c[i].v] couc c[i].v [i] c i v c[i].c [i] c i c if coua == couc:
     conc = "Stable"
else:
    conc = "Not stable" coua == couc coua couc conc = "Stable" conc "Stable" conc = "Not stable" conc "Not stable" print(conc) print conc c = a[:] a[:] c n = int(input()) int(input()) n conc = "Stable" "Stable" conc class card:

    def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

    def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q class card:

    def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

    def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q card coua = ["" for i in range(10)] ["" for i in range(10)] coua conc = "Not stable" "Not stable" conc b = a[:] a[:] b mini = j j mini conb = "" "" conb conb = "Stable" "Stable" conb coub = ["" for i in range(10)] ["" for i in range(10)] coub a = list(map(card, input().split())) list(map(card, input().split())) a mini = i i mini conc = "" "" conc couc = ["" for i in range(10)] ["" for i in range(10)] couc conb = "Not stable" "Not stable" conb
class card:

    def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

    def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q


n = int(input())
a = list(map(card, input().split()))


b = a[:]
c = a[:]

for i in range(n):
    for j in range(n-1, i, -1):
        if b[j].v < b[j-1].v:
            b[j], b[j-1] = b[j-1],b[j]

print(" ".join(x.self_str() for x in b))

coua = ["" for i in range(10)]
coub = ["" for i in range(10)]
conb = ""
for i in range(n):
    for j in range(n):
        if i != j:
            if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
            if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c
if coua == coub:
     conb = "Stable"
else:
    conb = "Not stable"
print(conb)





for i in range(n):
    mini = i
    for j in range(i, n):
        if c[j].v < c[mini].v:
            mini = j
    c[mini], c[i] = c[i], c[mini]

print(" ".join(x.self_str() for x in c))

couc = ["" for i in range(10)]
conc = ""
for i in range(n):
    for j in range(n):
        if i != j:
            if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c
if coua == couc:
     conc = "Stable"
else:
    conc = "Not stable"

print(conc)