def bubbleSort(A,N):
    for i in range(0,N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A

def selectionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A

if __name__ == '__main__':
    N = (int)(input())
    A1 = [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ]
    A2 = A1.copy()

    resultA1 = bubbleSort(A1,N)
    resultA2 = selectionSort(A2,N)

    outputA1 = ' '.join( [x[0]+(str)(x[1]) for x in resultA1])
    outputA2 = ' '.join( [x[0]+(str)(x[1]) for x in resultA2])

    print(outputA1)
    print("Stable")
    print(outputA2)
    if outputA1 == outputA2 :
        print("Stable")
    else:
        print("Not stable") def bubbleSort(A,N):
    for i in range(0,N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A bubbleSort for i in range(0,N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
     i range(0,N) range 0 N for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
     j range(N-1,i,-1) range N-1 N 1 i -1 if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
     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 v = A[j] v A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = v A[j-1] A j-1 j 1 v return A A A A N N def selectionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A selectionSort for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
     i range(0,N) range 0 N minj = i minj i for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
         j range(i,N) range i N if A[j][1] < A[minj][1]:
                minj = j
         A[j][1] < A[minj][1] A[j][1] [j] A j 1 A[minj][1] [minj] A minj 1 minj = j minj j v = A[i] v A[i] A i A[i] = A[minj] A[i] A i A[minj] A minj A[minj] = v A[minj] A minj v return A A A A N N if __name__ == '__main__':
    N = (int)(input())
    A1 = [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ]
    A2 = A1.copy()

    resultA1 = bubbleSort(A1,N)
    resultA2 = selectionSort(A2,N)

    outputA1 = ' '.join( [x[0]+(str)(x[1]) for x in resultA1])
    outputA2 = ' '.join( [x[0]+(str)(x[1]) for x in resultA2])

    print(outputA1)
    print("Stable")
    print(outputA2)
    if outputA1 == outputA2 :
        print("Stable")
    else:
        print("Not stable") __name__ == '__main__' __name__ '__main__' N = (int)(input()) N (int)(input()) int input() input [x[0],(int)(x[1])] for x in [list(x) for x in input().split()] for x in [list(x) for x in input().split()] x [list(x) for x in input().split()] for x in [list(x) for x in input().split()] [x[0],(int)(x[1])] x[0] x 0 (int)(x[1]) int x[1] x 1 A1 = [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ] A1 [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ] A2 = A1.copy() A2 A1.copy() A1.copy A1 copy resultA1 = bubbleSort(A1,N) resultA1 bubbleSort(A1,N) bubbleSort A1 N resultA2 = selectionSort(A2,N) resultA2 selectionSort(A2,N) selectionSort A2 N x[0]+(str)(x[1]) for x in resultA1 for x in resultA1 x resultA1 for x in resultA1 x[0]+(str)(x[1]) x[0] x 0 (str)(x[1]) str x[1] x 1 outputA1 = ' '.join( [x[0]+(str)(x[1]) for x in resultA1]) outputA1 ' '.join( [x[0]+(str)(x[1]) for x in resultA1]) ' '.join ' ' join [x[0]+(str)(x[1]) for x in resultA1] x[0]+(str)(x[1]) for x in resultA2 for x in resultA2 x resultA2 for x in resultA2 x[0]+(str)(x[1]) x[0] x 0 (str)(x[1]) str x[1] x 1 outputA2 = ' '.join( [x[0]+(str)(x[1]) for x in resultA2]) outputA2 ' '.join( [x[0]+(str)(x[1]) for x in resultA2]) ' '.join ' ' join [x[0]+(str)(x[1]) for x in resultA2] print(outputA1) print outputA1 print("Stable") print "Stable" print(outputA2) print outputA2 if outputA1 == outputA2 :
        print("Stable")
    else:
        print("Not stable") outputA1 == outputA2 outputA1 outputA2 print("Stable") print "Stable" print("Not stable") print "Not stable" N = (int)(input()) (int)(input()) N outputA1 = ' '.join( [x[0]+(str)(x[1]) for x in resultA1]) ' '.join( [x[0]+(str)(x[1]) for x in resultA1]) outputA1 def selectionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A def selectionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A selectionSort A2 = A1.copy() A1.copy() A2 outputA2 = ' '.join( [x[0]+(str)(x[1]) for x in resultA2]) ' '.join( [x[0]+(str)(x[1]) for x in resultA2]) outputA2 A1 = [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ] [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ] A1 resultA1 = bubbleSort(A1,N) bubbleSort(A1,N) resultA1 resultA2 = selectionSort(A2,N) selectionSort(A2,N) resultA2 def bubbleSort(A,N):
    for i in range(0,N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A def bubbleSort(A,N):
    for i in range(0,N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A bubbleSort
def bubbleSort(A,N):
    for i in range(0,N):
        for j in range(N-1,i,-1):
            if A[j][1] < A[j-1][1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
    return A

def selectionSort(A,N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
    return A

if __name__ == '__main__':
    N = (int)(input())
    A1 = [[x[0],(int)(x[1])] for x in [list(x) for x in input().split()] ]
    A2 = A1.copy()

    resultA1 = bubbleSort(A1,N)
    resultA2 = selectionSort(A2,N)

    outputA1 = ' '.join( [x[0]+(str)(x[1]) for x in resultA1])
    outputA2 = ' '.join( [x[0]+(str)(x[1]) for x in resultA2])

    print(outputA1)
    print("Stable")
    print(outputA2)
    if outputA1 == outputA2 :
        print("Stable")
    else:
        print("Not stable")