def BubbleSort(C, N):
    for i in xrange(0,N):
        for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
    return C

def SelectionSort(C, N):
    for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
    return C

def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True

def main():
    N = int(raw_input())
    A = raw_input().split()
    BA = BubbleSort(A[:], N)
    SA = SelectionSort(A[:], N)
    print ' '.join(BA)
    if isStable(A, BA,N):
        print "Stable"
    else:
        print "Not stable"
    print ' '.join(SA)
    if isStable(A, SA,N):
        print "Stable"
    else:
        print "Not stable"

    return 0

if __name__ == "__main__":
    main() def BubbleSort(C, N):
    for i in xrange(0,N):
        for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
    return C BubbleSort for i in xrange(0,N):
        for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
     i xrange(0,N) xrange 0 N for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
     j xrange(N-1,i,-1) xrange N-1 N 1 i -1 if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
     int(C[j][1]) < int(C[j-1][1]) int(C[j][1]) int C[j][1] [j] C j 1 int(C[j-1][1]) int C[j-1][1] [j-1] C j-1 j 1 1 tmp = C[j] tmp C[j] C j C[j] = C[j-1] C[j] C j C[j-1] C j-1 j 1 C[j-1] = tmp C[j-1] C j-1 j 1 tmp return C C C C N N def SelectionSort(C, N):
    for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
    return C SelectionSort for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
     i xrange(0,N) xrange 0 N minj = i minj i for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
         j xrange(i,N) xrange i N if int(C[j][1]) < int(C[minj][1]):
                minj = j
         int(C[j][1]) < int(C[minj][1]) int(C[j][1]) int C[j][1] [j] C j 1 int(C[minj][1]) int C[minj][1] [minj] C minj 1 minj = j minj j if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
     minj != i minj i tmp = C[i] tmp C[i] C i C[i] = C[minj] C[i] C i C[minj] C minj C[minj] = tmp C[minj] C minj tmp return C C C C N N def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True isStable for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     i xrange(N) xrange N for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     j xrange(i + 1, N) xrange i + 1 i 1 N for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     a xrange(N) xrange N for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     b xrange(a + 1, N) xrange a + 1 a 1 N if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
     in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a] in_[i][1] == in_[j][1] and in_[i] == out_[b] in_[i][1] == in_[j][1] in_[i][1] [i] in_ i 1 in_[j][1] [j] in_ j 1 in_[i] == out_[b] in_[i] in_ i out_[b] out_ b in_[j] == out_[a] in_[j] in_ j out_[a] out_ a return False False return True True in_ in_ out_ out_ N N def main():
    N = int(raw_input())
    A = raw_input().split()
    BA = BubbleSort(A[:], N)
    SA = SelectionSort(A[:], N)
    print ' '.join(BA)
    if isStable(A, BA,N):
        print "Stable"
    else:
        print "Not stable"
    print ' '.join(SA)
    if isStable(A, SA,N):
        print "Stable"
    else:
        print "Not stable"

    return 0 main N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = raw_input().split() A raw_input().split() ().split () raw_input split BA = BubbleSort(A[:], N) BA BubbleSort(A[:], N) BubbleSort A[:] A : N SA = SelectionSort(A[:], N) SA SelectionSort(A[:], N) SelectionSort A[:] A : N print ' '.join(BA) ' '.join ' ' join BA if isStable(A, BA,N):
        print "Stable"
    else:
        print "Not stable"
     isStable(A, BA,N) isStable A BA N print print print ' '.join(SA) ' '.join ' ' join SA if isStable(A, SA,N):
        print "Stable"
    else:
        print "Not stable"

     isStable(A, SA,N) isStable A SA N print print return 0 0 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N = int(raw_input())
    A = raw_input().split()
    BA = BubbleSort(A[:], N)
    SA = SelectionSort(A[:], N)
    print ' '.join(BA)
    if isStable(A, BA,N):
        print "Stable"
    else:
        print "Not stable"
    print ' '.join(SA)
    if isStable(A, SA,N):
        print "Stable"
    else:
        print "Not stable"

    return 0 def main():
    N = int(raw_input())
    A = raw_input().split()
    BA = BubbleSort(A[:], N)
    SA = SelectionSort(A[:], N)
    print ' '.join(BA)
    if isStable(A, BA,N):
        print "Stable"
    else:
        print "Not stable"
    print ' '.join(SA)
    if isStable(A, SA,N):
        print "Stable"
    else:
        print "Not stable"

    return 0 main def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True isStable def SelectionSort(C, N):
    for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
    return C def SelectionSort(C, N):
    for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
    return C SelectionSort def BubbleSort(C, N):
    for i in xrange(0,N):
        for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
    return C def BubbleSort(C, N):
    for i in xrange(0,N):
        for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
    return C BubbleSort
def BubbleSort(C, N):
    for i in xrange(0,N):
        for j in xrange(N-1,i,-1):
            if int(C[j][1]) < int(C[j-1][1]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
    return C

def SelectionSort(C, N):
    for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        if minj != i:
            tmp = C[i]
            C[i] = C[minj]
            C[minj] = tmp
    return C

def isStable(in_, out_, N):
    for i in xrange(N):
        for j in xrange(i + 1, N):
            for a in xrange(N):
                for b in xrange(a + 1, N):
                    if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
                        return False
    return True

def main():
    N = int(raw_input())
    A = raw_input().split()
    BA = BubbleSort(A[:], N)
    SA = SelectionSort(A[:], N)
    print ' '.join(BA)
    if isStable(A, BA,N):
        print "Stable"
    else:
        print "Not stable"
    print ' '.join(SA)
    if isStable(A, SA,N):
        print "Stable"
    else:
        print "Not stable"

    return 0

if __name__ == "__main__":
    main()