n = int(input())
a = [i for i in input().split()]
a2 = a.copy()
for i in range(n):
    for j in reversed(range(i+1, n)):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
for s in range(n):
    minj = s 
    for t in range(s+1, n):
        if a2[t][1] < a2[minj][1]:
            minj = t
    if a2[s] != a2[minj]:
        a2[s], a2[minj] = a2[minj], a2[s]
print(*a)
print("Stable")
print(*a2)
if a == a2:
    print("Stable")
else:
    print("Not stable") n = int(input()) n int(input()) int input() input i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i a = [i for i in input().split()] a [i for i in input().split()] a2 = a.copy() a2 a.copy() a.copy a copy for i in range(n):
    for j in reversed(range(i+1, n)):
        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 reversed(range(i+1, n)):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j] j reversed(range(i+1, n)) reversed range(i+1, n) range i+1 i 1 n 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 for s in range(n):
    minj = s 
    for t in range(s+1, n):
        if a2[t][1] < a2[minj][1]:
            minj = t
    if a2[s] != a2[minj]:
        a2[s], a2[minj] = a2[minj], a2[s] s range(n) range n minj = s minj s for t in range(s+1, n):
        if a2[t][1] < a2[minj][1]:
            minj = t
     t range(s+1, n) range s+1 s 1 n if a2[t][1] < a2[minj][1]:
            minj = t
     a2[t][1] < a2[minj][1] a2[t][1] [t] a2 t 1 a2[minj][1] [minj] a2 minj 1 minj = t minj t if a2[s] != a2[minj]:
        a2[s], a2[minj] = a2[minj], a2[s] a2[s] != a2[minj] a2[s] a2 s a2[minj] a2 minj a2[s], a2[minj] = a2[minj], a2[s] a2[s] a2 s a2[minj] a2 minj a2[minj] a2 minj a2[s] a2 s print(*a) print *a a print("Stable") print "Stable" print(*a2) print *a2 a2 if a == a2:
    print("Stable")
else:
    print("Not stable") a == a2 a a2 print("Stable") print "Stable" print("Not stable") print "Not stable" a = [i for i in input().split()] [i for i in input().split()] a n = int(input()) int(input()) n minj = t t minj a2 = a.copy() a.copy() a2 minj = s s minj
n = int(input())
a = [i for i in input().split()]
a2 = a.copy()
for i in range(n):
    for j in reversed(range(i+1, n)):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
for s in range(n):
    minj = s 
    for t in range(s+1, n):
        if a2[t][1] < a2[minj][1]:
            minj = t
    if a2[s] != a2[minj]:
        a2[s], a2[minj] = a2[minj], a2[s]
print(*a)
print("Stable")
print(*a2)
if a == a2:
    print("Stable")
else:
    print("Not stable")
