N = int(input())
l = input().split()
l2 = l[:]
for j in range(N):
    for i in range(N-1):
        if l[i][1] > l[i+1][1]:
            l[i], l[i+1] = l[i+1], l[i]
for i in range(0,len(l)-1):
    print(l[i],end=' ')
print(l[N-1])
print("Stable")

for j in range(0,len(l2)-1):
    min = l2[j][1]
    a = j
    for i in range(j,len(l2)):
        if min > l2[i][1]:
            min = l2[i][1]
            a = i
    l2[j],l2[a] = l2[a],l2[j]
for i in range(0,len(l2)-1):
    print(l2[i],end=' ')
print(l2[N-1])
if l==l2:
    print("Stable")
else:
    print("Not stable")
 N = int(input()) N int(input()) int input() input l = input().split() l input().split() ().split () input split l2 = l[:] l2 l[:] l : for j in range(N):
    for i in range(N-1):
        if l[i][1] > l[i+1][1]:
            l[i], l[i+1] = l[i+1], l[i] j range(N) range N for i in range(N-1):
        if l[i][1] > l[i+1][1]:
            l[i], l[i+1] = l[i+1], l[i] i range(N-1) range N-1 N 1 if l[i][1] > l[i+1][1]:
            l[i], l[i+1] = l[i+1], l[i] l[i][1] > l[i+1][1] l[i][1] [i] l i 1 l[i+1][1] [i+1] l i+1 i 1 1 l[i], l[i+1] = l[i+1], l[i] l[i] l i l[i+1] l i+1 i 1 l[i+1] l i+1 i 1 l[i] l i for i in range(0,len(l)-1):
    print(l[i],end=' ') i range(0,len(l)-1) range 0 len(l)-1 len(l) len l 1 print(l[i],end=' ') print l[i] l i end=' ' end ' ' print(l[N-1]) print l[N-1] l N-1 N 1 print("Stable") print "Stable" for j in range(0,len(l2)-1):
    min = l2[j][1]
    a = j
    for i in range(j,len(l2)):
        if min > l2[i][1]:
            min = l2[i][1]
            a = i
    l2[j],l2[a] = l2[a],l2[j] j range(0,len(l2)-1) range 0 len(l2)-1 len(l2) len l2 1 min = l2[j][1] min l2[j][1] [j] l2 j 1 a = j a j for i in range(j,len(l2)):
        if min > l2[i][1]:
            min = l2[i][1]
            a = i
     i range(j,len(l2)) range j len(l2) len l2 if min > l2[i][1]:
            min = l2[i][1]
            a = i
     min > l2[i][1] min l2[i][1] [i] l2 i 1 min = l2[i][1] min l2[i][1] [i] l2 i 1 a = i a i l2[j],l2[a] = l2[a],l2[j] l2[j] l2 j l2[a] l2 a l2[a] l2 a l2[j] l2 j for i in range(0,len(l2)-1):
    print(l2[i],end=' ') i range(0,len(l2)-1) range 0 len(l2)-1 len(l2) len l2 1 print(l2[i],end=' ') print l2[i] l2 i end=' ' end ' ' print(l2[N-1]) print l2[N-1] l2 N-1 N 1 if l==l2:
    print("Stable")
else:
    print("Not stable") l==l2 l l2 print("Stable") print "Stable" print("Not stable") print "Not stable" a = i i a min = l2[j][1] l2[j][1] min l = input().split() input().split() l a = j j a min = l2[i][1] l2[i][1] min l2 = l[:] l[:] l2 N = int(input()) int(input()) N
N = int(input())
l = input().split()
l2 = l[:]
for j in range(N):
    for i in range(N-1):
        if l[i][1] > l[i+1][1]:
            l[i], l[i+1] = l[i+1], l[i]
for i in range(0,len(l)-1):
    print(l[i],end=' ')
print(l[N-1])
print("Stable")

for j in range(0,len(l2)-1):
    min = l2[j][1]
    a = j
    for i in range(j,len(l2)):
        if min > l2[i][1]:
            min = l2[i][1]
            a = i
    l2[j],l2[a] = l2[a],l2[j]
for i in range(0,len(l2)-1):
    print(l2[i],end=' ')
print(l2[N-1])
if l==l2:
    print("Stable")
else:
    print("Not stable")

