def bubbleSort(C1,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
    return C1[:]
    
def selectSort(C2,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
        C2[i],C2[minj] = C2[minj],C2[i]
    return C2[:]

N = int(input())
C1 = input().split()
C2 = C1[:]

C1 = bubbleSort(C1,N)
C2 = selectSort(C2,N)

print(*C1)
print("Stable")
print(*C2)
if C1 == C2:
    print("Stable")
else:
    print("Not stable") def bubbleSort(C1,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
    return C1[:]
     bubbleSort for i in range(N):
        for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
     i range(N) range N for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
     j range(N-1,i,-1) range N-1 N 1 i -1 if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
     C1[j][1] < C1[j-1][1] C1[j][1] [j] C1 j 1 C1[j-1][1] [j-1] C1 j-1 j 1 1 C1[j],C1[j-1] = C1[j-1],C1[j] C1[j] C1 j C1[j-1] C1 j-1 j 1 C1[j-1] C1 j-1 j 1 C1[j] C1 j return C1[:] C1[:] C1 : C1 C1 N N def selectSort(C2,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
        C2[i],C2[minj] = C2[minj],C2[i]
    return C2[:] selectSort for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
        C2[i],C2[minj] = C2[minj],C2[i]
     i range(0,N) range 0 N minj = i minj i for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
         j range(i,N) range i N if C2[minj][1] > C2[j][1]:
                minj = j
         C2[minj][1] > C2[j][1] C2[minj][1] [minj] C2 minj 1 C2[j][1] [j] C2 j 1 minj = j minj j C2[i],C2[minj] = C2[minj],C2[i] C2[i] C2 i C2[minj] C2 minj C2[minj] C2 minj C2[i] C2 i return C2[:] C2[:] C2 : C2 C2 N N N = int(input()) N int(input()) int input() input C1 = input().split() C1 input().split() ().split () input split C2 = C1[:] C2 C1[:] C1 : C1 = bubbleSort(C1,N) C1 bubbleSort(C1,N) bubbleSort C1 N C2 = selectSort(C2,N) C2 selectSort(C2,N) selectSort C2 N print(*C1) print *C1 C1 print("Stable") print "Stable" print(*C2) print *C2 C2 if C1 == C2:
    print("Stable")
else:
    print("Not stable") C1 == C2 C1 C2 print("Stable") print "Stable" print("Not stable") print "Not stable" C2 = selectSort(C2,N) selectSort(C2,N) C2 C1 = bubbleSort(C1,N) bubbleSort(C1,N) C1 N = int(input()) int(input()) N def selectSort(C2,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
        C2[i],C2[minj] = C2[minj],C2[i]
    return C2[:] def selectSort(C2,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
        C2[i],C2[minj] = C2[minj],C2[i]
    return C2[:] selectSort def bubbleSort(C1,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
    return C1[:]
     def bubbleSort(C1,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
    return C1[:]
     bubbleSort C1 = input().split() input().split() C1 C2 = C1[:] C1[:] C2
def bubbleSort(C1,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if C1[j][1] < C1[j-1][1]:
                C1[j],C1[j-1] = C1[j-1],C1[j]
    return C1[:]
    
def selectSort(C2,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C2[minj][1] > C2[j][1]:
                minj = j
        C2[i],C2[minj] = C2[minj],C2[i]
    return C2[:]

N = int(input())
C1 = input().split()
C2 = C1[:]

C1 = bubbleSort(C1,N)
C2 = selectSort(C2,N)

print(*C1)
print("Stable")
print(*C2)
if C1 == C2:
    print("Stable")
else:
    print("Not stable")
