import copy

n = int(input())
a = input().split()
b = copy.deepcopy(a)

for i in range(n):
    for j in range(n - 1 - i):
        if int(a[j][1]) > int(a[j + 1][1]):
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp

ra = " ".join(a)

print(ra)
print("Stable")

for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if int(b[j][1]) < int(b[minj][1]):
            minj = j
    if minj != i:
        tmp = b[i]
        b[i] = b[minj]
        b[minj] = tmp

rb = " ".join(b)
print(rb)

if ra == rb:
    print("Stable")
else:
    print("Not stable") import copy copy n = int(input()) n int(input()) int input() input a = input().split() a input().split() ().split () input split b = copy.deepcopy(a) b copy.deepcopy(a) copy.deepcopy copy deepcopy a for i in range(n):
    for j in range(n - 1 - i):
        if int(a[j][1]) > int(a[j + 1][1]):
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp i range(n) range n for j in range(n - 1 - i):
        if int(a[j][1]) > int(a[j + 1][1]):
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp j range(n - 1 - i) range n - 1 - i n - 1 n 1 i if int(a[j][1]) > int(a[j + 1][1]):
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp int(a[j][1]) > int(a[j + 1][1]) int(a[j][1]) int a[j][1] [j] a j 1 int(a[j + 1][1]) int a[j + 1][1] [j + 1] a j + 1 j 1 1 tmp = a[j] tmp a[j] a j a[j] = a[j + 1] a[j] a j a[j + 1] a j + 1 j 1 a[j + 1] = tmp a[j + 1] a j + 1 j 1 tmp ra = " ".join(a) ra " ".join(a) " ".join " " join a print(ra) print ra print("Stable") print "Stable" for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if int(b[j][1]) < int(b[minj][1]):
            minj = j
    if minj != i:
        tmp = b[i]
        b[i] = b[minj]
        b[minj] = tmp i range(n - 1) range n - 1 n 1 minj = i minj i for j in range(i + 1, n):
        if int(b[j][1]) < int(b[minj][1]):
            minj = j
     j range(i + 1, n) range i + 1 i 1 n if int(b[j][1]) < int(b[minj][1]):
            minj = j
     int(b[j][1]) < int(b[minj][1]) int(b[j][1]) int b[j][1] [j] b j 1 int(b[minj][1]) int b[minj][1] [minj] b minj 1 minj = j minj j if minj != i:
        tmp = b[i]
        b[i] = b[minj]
        b[minj] = tmp minj != i minj i tmp = b[i] tmp b[i] b i b[i] = b[minj] b[i] b i b[minj] b minj b[minj] = tmp b[minj] b minj tmp rb = " ".join(b) rb " ".join(b) " ".join " " join b print(rb) print rb if ra == rb:
    print("Stable")
else:
    print("Not stable") ra == rb ra rb print("Stable") print "Stable" print("Not stable") print "Not stable" tmp = a[j] a[j] tmp a = input().split() input().split() a n = int(input()) int(input()) n ra = " ".join(a) " ".join(a) ra rb = " ".join(b) " ".join(b) rb b = copy.deepcopy(a) copy.deepcopy(a) b minj = i i minj tmp = b[i] b[i] tmp minj = j j minj
import copy

n = int(input())
a = input().split()
b = copy.deepcopy(a)

for i in range(n):
    for j in range(n - 1 - i):
        if int(a[j][1]) > int(a[j + 1][1]):
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp

ra = " ".join(a)

print(ra)
print("Stable")

for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if int(b[j][1]) < int(b[minj][1]):
            minj = j
    if minj != i:
        tmp = b[i]
        b[i] = b[minj]
        b[minj] = tmp

rb = " ".join(b)
print(rb)

if ra == rb:
    print("Stable")
else:
    print("Not stable")