n = int(input())
c = input().split()
d = c[:]

# bubblesort
for i in range(n):
    for j in range(n - 1, i, -1):
        if d[j][1] < d[j - 1][1]:
            d[j], d[j - 1] = d[j - 1], d[j]
print(*d)
print("Stable")

# selectionsort
for i in range(n):
    minj = i
    for j in range(i, n):
        if c[j][1] < c[minj][1]:
            minj = j
    c[i], c[minj] = c[minj], c[i]

print(*c)
print("Stable" if c == d else "Not stable") n = int(input()) n int(input()) int input() input c = input().split() c input().split() ().split () input split d = c[:] d c[:] c : for i in range(n):
    for j in range(n - 1, i, -1):
        if d[j][1] < d[j - 1][1]:
            d[j], d[j - 1] = d[j - 1], d[j] i range(n) range n for j in range(n - 1, i, -1):
        if d[j][1] < d[j - 1][1]:
            d[j], d[j - 1] = d[j - 1], d[j] j range(n - 1, i, -1) range n - 1 n 1 i -1 if d[j][1] < d[j - 1][1]:
            d[j], d[j - 1] = d[j - 1], d[j] d[j][1] < d[j - 1][1] d[j][1] [j] d j 1 d[j - 1][1] [j - 1] d j - 1 j 1 1 d[j], d[j - 1] = d[j - 1], d[j] d[j] d j d[j - 1] d j - 1 j 1 d[j - 1] d j - 1 j 1 d[j] d j print(*d) print *d d print("Stable") print "Stable" for i in range(n):
    minj = i
    for j in range(i, n):
        if c[j][1] < c[minj][1]:
            minj = j
    c[i], c[minj] = c[minj], c[i] i range(n) range n minj = i minj i for j in range(i, n):
        if c[j][1] < c[minj][1]:
            minj = j
     j range(i, n) range i n if c[j][1] < c[minj][1]:
            minj = j
     c[j][1] < c[minj][1] c[j][1] [j] c j 1 c[minj][1] [minj] c minj 1 minj = j minj j c[i], c[minj] = c[minj], c[i] c[i] c i c[minj] c minj c[minj] c minj c[i] c i print(*c) print *c c print("Stable" if c == d else "Not stable") print "Stable" if c == d else "Not stable" c == d c d "Stable" "Not stable" n = int(input()) int(input()) n c = input().split() input().split() c minj = j j minj minj = i i minj d = c[:] c[:] d
n = int(input())
c = input().split()
d = c[:]

# bubblesort
for i in range(n):
    for j in range(n - 1, i, -1):
        if d[j][1] < d[j - 1][1]:
            d[j], d[j - 1] = d[j - 1], d[j]
print(*d)
print("Stable")

# selectionsort
for i in range(n):
    minj = i
    for j in range(i, n):
        if c[j][1] < c[minj][1]:
            minj = j
    c[i], c[minj] = c[minj], c[i]

print(*c)
print("Stable" if c == d else "Not stable")