# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:01:05 2017

@author: syaga
"""

if __name__ == "__main__":
    N = int(input())
    C = list(input().split())
    D = C[:]

    # Bunbble Sort
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                temp = C[j]
                C[j] = C[j-1]
                C[j-1] = temp
    print(" ".join(C))
    print("Stable")

    # Selection Sort
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(D[j][1]) < int(D[minj][1]):
                minj = j
        temp = D[i]
        D[i] = D[minj]
        D[minj] = temp
    print(" ".join(D))
    flag = 0
    for (i, j) in zip(C, D):
        if i != j:
            flag = 1
            break
    if flag == 1:
        print("Not stable")
    else:
        print("Stable") """
Created on Sun Jun 18 10:01:05 2017

@author: syaga
""" if __name__ == "__main__":
    N = int(input())
    C = list(input().split())
    D = C[:]

    # Bunbble Sort
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                temp = C[j]
                C[j] = C[j-1]
                C[j-1] = temp
    print(" ".join(C))
    print("Stable")

    # Selection Sort
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(D[j][1]) < int(D[minj][1]):
                minj = j
        temp = D[i]
        D[i] = D[minj]
        D[minj] = temp
    print(" ".join(D))
    flag = 0
    for (i, j) in zip(C, D):
        if i != j:
            flag = 1
            break
    if flag == 1:
        print("Not stable")
    else:
        print("Stable") __name__ == "__main__" __name__ "__main__" N = int(input()) N int(input()) int input() input C = list(input().split()) C list(input().split()) list input().split() ().split () input split D = C[:] D C[:] C : for i in range(0, N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                temp = C[j]
                C[j] = C[j-1]
                C[j-1] = temp
     i range(0, N) range 0 N for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                temp = C[j]
                C[j] = C[j-1]
                C[j-1] = temp
     j range(N-1, i, -1) range N-1 N 1 i -1 if int(C[j][1]) < int(C[j-1][1]):
                temp = C[j]
                C[j] = C[j-1]
                C[j-1] = temp
     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 temp = C[j] temp C[j] C j C[j] = C[j-1] C[j] C j C[j-1] C j-1 j 1 C[j-1] = temp C[j-1] C j-1 j 1 temp print(" ".join(C)) print " ".join(C) " ".join " " join C print("Stable") print "Stable" for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(D[j][1]) < int(D[minj][1]):
                minj = j
        temp = D[i]
        D[i] = D[minj]
        D[minj] = temp
     i range(0, N) range 0 N minj = i minj i for j in range(i, N):
            if int(D[j][1]) < int(D[minj][1]):
                minj = j
         j range(i, N) range i N if int(D[j][1]) < int(D[minj][1]):
                minj = j
         int(D[j][1]) < int(D[minj][1]) int(D[j][1]) int D[j][1] [j] D j 1 int(D[minj][1]) int D[minj][1] [minj] D minj 1 minj = j minj j temp = D[i] temp D[i] D i D[i] = D[minj] D[i] D i D[minj] D minj D[minj] = temp D[minj] D minj temp print(" ".join(D)) print " ".join(D) " ".join " " join D flag = 0 flag 0 for (i, j) in zip(C, D):
        if i != j:
            flag = 1
            break
     (i, j) i j zip(C, D) zip C D if i != j:
            flag = 1
            break
     i != j i j flag = 1 flag 1 break if flag == 1:
        print("Not stable")
    else:
        print("Stable") flag == 1 flag 1 print("Not stable") print "Not stable" print("Stable") print "Stable" minj = i i minj flag = 0 0 flag N = int(input()) int(input()) N temp = D[i] D[i] temp minj = j j minj C = list(input().split()) list(input().split()) C temp = C[j] C[j] temp flag = 1 1 flag D = C[:] C[:] D
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:01:05 2017

@author: syaga
"""

if __name__ == "__main__":
    N = int(input())
    C = list(input().split())
    D = C[:]

    # Bunbble Sort
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                temp = C[j]
                C[j] = C[j-1]
                C[j-1] = temp
    print(" ".join(C))
    print("Stable")

    # Selection Sort
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(D[j][1]) < int(D[minj][1]):
                minj = j
        temp = D[i]
        D[i] = D[minj]
        D[minj] = temp
    print(" ".join(D))
    flag = 0
    for (i, j) in zip(C, D):
        if i != j:
            flag = 1
            break
    if flag == 1:
        print("Not stable")
    else:
        print("Stable")