N = int(input())

C = input().split()

B = C[:]
S = C[:]

# bubble sort
flag = 1
while(flag):
    flag = 0
    for x in range(1, N):
        if B[x][1:] < B[x-1][1:]:
            B[x], B[x-1] = B[x-1], B[x]
            flag = 1

# sectionSot
for x in range(0,N):
    minj = x
    for j in range(x,N):
        if S[j][1:] < S[minj][1:]:
            minj = j
    if minj != x:
        S[x], S[minj] = S[minj], S[x]



print(" ".join(b for b in B))
print("Stable")


if(B == S):
    print(" ".join(b for b in S))
    print("Stable")
else:
    print(" ".join(b for b in S))
    print("Not stable") N = int(input()) N int(input()) int input() input C = input().split() C input().split() ().split () input split B = C[:] B C[:] C : S = C[:] S C[:] C : flag = 1 flag 1 while(flag):
    flag = 0
    for x in range(1, N):
        if B[x][1:] < B[x-1][1:]:
            B[x], B[x-1] = B[x-1], B[x]
            flag = 1

# sectionSot flag flag = 0 flag 0 for x in range(1, N):
        if B[x][1:] < B[x-1][1:]:
            B[x], B[x-1] = B[x-1], B[x]
            flag = 1

# sectionSot x range(1, N) range 1 N if B[x][1:] < B[x-1][1:]:
            B[x], B[x-1] = B[x-1], B[x]
            flag = 1

# sectionSot B[x][1:] < B[x-1][1:] B[x][1:] [x] B x 1: 1 B[x-1][1:] [x-1] B x-1 x 1 1: 1 B[x], B[x-1] = B[x-1], B[x] B[x] B x B[x-1] B x-1 x 1 B[x-1] B x-1 x 1 B[x] B x flag = 1 flag 1 for x in range(0,N):
    minj = x
    for j in range(x,N):
        if S[j][1:] < S[minj][1:]:
            minj = j
    if minj != x:
        S[x], S[minj] = S[minj], S[x] x range(0,N) range 0 N minj = x minj x for j in range(x,N):
        if S[j][1:] < S[minj][1:]:
            minj = j
     j range(x,N) range x N if S[j][1:] < S[minj][1:]:
            minj = j
     S[j][1:] < S[minj][1:] S[j][1:] [j] S j 1: 1 S[minj][1:] [minj] S minj 1: 1 minj = j minj j if minj != x:
        S[x], S[minj] = S[minj], S[x] minj != x minj x S[x], S[minj] = S[minj], S[x] S[x] S x S[minj] S minj S[minj] S minj S[x] S x print(" ".join(b for b in B)) print " ".join(b for b in B) " ".join " " join b print("Stable") print "Stable" if(B == S):
    print(" ".join(b for b in S))
    print("Stable")
else:
    print(" ".join(b for b in S))
    print("Not stable") B == S B S print(" ".join(b for b in S)) print " ".join(b for b in S) " ".join " " join b print("Stable") print "Stable" print(" ".join(b for b in S)) print " ".join(b for b in S) " ".join " " join b print("Not stable") print "Not stable" C = input().split() input().split() C flag = 1 1 flag B = C[:] C[:] B S = C[:] C[:] S flag = 0 0 flag N = int(input()) int(input()) N minj = x x minj flag = 1 1 flag minj = j j minj
N = int(input())

C = input().split()

B = C[:]
S = C[:]

# bubble sort
flag = 1
while(flag):
    flag = 0
    for x in range(1, N):
        if B[x][1:] < B[x-1][1:]:
            B[x], B[x-1] = B[x-1], B[x]
            flag = 1

# sectionSot
for x in range(0,N):
    minj = x
    for j in range(x,N):
        if S[j][1:] < S[minj][1:]:
            minj = j
    if minj != x:
        S[x], S[minj] = S[minj], S[x]



print(" ".join(b for b in B))
print("Stable")


if(B == S):
    print(" ".join(b for b in S))
    print("Stable")
else:
    print(" ".join(b for b in S))
    print("Not stable")