N = int(input())
B = input().split()
S = B[:]

for i in range(N):
    for j in range(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
    
    m = i
    for j in range(i, N):
        if S[m][1] > S[j][1]:
            m = j
    S[m], S[i] = S[i], S[m]

print(*B)
print('Stable')
print(*S)
print(['Not s', 'S'][B==S] + 'table') N = int(input()) N int(input()) int input() input B = input().split() B input().split() ().split () input split S = B[:] S B[:] B : for i in range(N):
    for j in range(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
    
    m = i
    for j in range(i, N):
        if S[m][1] > S[j][1]:
            m = j
    S[m], S[i] = S[i], S[m] i range(N) range N for j in range(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
    
     j range(N-1, i, -1) range N-1 N 1 i -1 if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
    
     B[j][1] < B[j-1][1] B[j][1] [j] B j 1 B[j-1][1] [j-1] B j-1 j 1 1 B[j], B[j-1] = B[j-1], B[j] B[j] B j B[j-1] B j-1 j 1 B[j-1] B j-1 j 1 B[j] B j m = i m i for j in range(i, N):
        if S[m][1] > S[j][1]:
            m = j
     j range(i, N) range i N if S[m][1] > S[j][1]:
            m = j
     S[m][1] > S[j][1] S[m][1] [m] S m 1 S[j][1] [j] S j 1 m = j m j S[m], S[i] = S[i], S[m] S[m] S m S[i] S i S[i] S i S[m] S m print(*B) print *B B print('Stable') print 'Stable' print(*S) print *S S print(['Not s', 'S'][B==S] + 'table') print ['Not s', 'S'][B==S] + 'table' ['Not s', 'S'][B==S] ['Not s', 'S'] 'Not s' 'S' B==S B S 'table' B = input().split() input().split() B S = B[:] B[:] S m = i i m N = int(input()) int(input()) N m = j j m
N = int(input())
B = input().split()
S = B[:]

for i in range(N):
    for j in range(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
    
    m = i
    for j in range(i, N):
        if S[m][1] > S[j][1]:
            m = j
    S[m], S[i] = S[i], S[m]

print(*B)
print('Stable')
print(*S)
print(['Not s', 'S'][B==S] + 'table')