N = int(input())
a = [(s[0], int(s[1])) for s in input().split()]

def bubble(a):
    n = len(a)
    for i in range(n):
        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]
    return a

def selection(a):
    n = len(a)
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a

b_a = bubble(a[:])
s_a = selection(a[:])

print(" ".join([p[0]+str(p[1]) for p in b_a]))
print("Stable")
print(" ".join([p[0]+str(p[1]) for p in s_a]))
print("Stable" if b_a==s_a else "Not stable") N = int(input()) N int(input()) int input() input (s[0], int(s[1])) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() (s[0], int(s[1])) s[0] s 0 int(s[1]) int s[1] s 1 a = [(s[0], int(s[1])) for s in input().split()] a [(s[0], int(s[1])) for s in input().split()] def bubble(a):
    n = len(a)
    for i in range(n):
        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]
    return a bubble n = len(a) n len(a) len a for i in range(n):
        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]
     i range(n) range n 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]
     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 return a a a a def selection(a):
    n = len(a)
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a selection n = len(a) n len(a) len a for i in range(n):
        minj = i
        for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]

     i range(n) range n minj = i minj i for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
         j range(i+1, n) range i+1 i 1 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 a[i], a[minj] = a[minj], a[i] a[i] a i a[minj] a minj a[minj] a minj a[i] a i return a a a a b_a = bubble(a[:]) b_a bubble(a[:]) bubble a[:] a : s_a = selection(a[:]) s_a selection(a[:]) selection a[:] a : p[0]+str(p[1]) for p in b_a for p in b_a p b_a for p in b_a p[0]+str(p[1]) p[0] p 0 str(p[1]) str p[1] p 1 print(" ".join([p[0]+str(p[1]) for p in b_a])) print " ".join([p[0]+str(p[1]) for p in b_a]) " ".join " " join [p[0]+str(p[1]) for p in b_a] print("Stable") print "Stable" p[0]+str(p[1]) for p in s_a for p in s_a p s_a for p in s_a p[0]+str(p[1]) p[0] p 0 str(p[1]) str p[1] p 1 print(" ".join([p[0]+str(p[1]) for p in s_a])) print " ".join([p[0]+str(p[1]) for p in s_a]) " ".join " " join [p[0]+str(p[1]) for p in s_a] print("Stable" if b_a==s_a else "Not stable") print "Stable" if b_a==s_a else "Not stable" b_a==s_a b_a s_a "Stable" "Not stable" b_a = bubble(a[:]) bubble(a[:]) b_a def bubble(a):
    n = len(a)
    for i in range(n):
        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]
    return a def bubble(a):
    n = len(a)
    for i in range(n):
        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]
    return a bubble s_a = selection(a[:]) selection(a[:]) s_a N = int(input()) int(input()) N def selection(a):
    n = len(a)
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a def selection(a):
    n = len(a)
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a selection a = [(s[0], int(s[1])) for s in input().split()] [(s[0], int(s[1])) for s in input().split()] a
N = int(input())
a = [(s[0], int(s[1])) for s in input().split()]

def bubble(a):
    n = len(a)
    for i in range(n):
        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]
    return a

def selection(a):
    n = len(a)
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a

b_a = bubble(a[:])
s_a = selection(a[:])

print(" ".join([p[0]+str(p[1]) for p in b_a]))
print("Stable")
print(" ".join([p[0]+str(p[1]) for p in s_a]))
print("Stable" if b_a==s_a else "Not stable")