N = int(raw_input())
line = raw_input()
A = line.strip().split(" ")
A2 = line.strip().split(" ")
for i in range(0, N):
    min_j = i
    for j in range(i, N):
        if int(A2[j][1:]) < int(A2[min_j][1:]):
            min_j = j
    A2[i], A2[min_j] = A2[min_j], A2[i]
select = " ".join(A2)
flag = True
while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if int(A[j][1:]) < int(A[j-1][1:]):
            A[j], A[j-1] = A[j-1], A[j]
            flag = True
bubble = " ".join(A)
print bubble
print "Stable"
print select
if bubble == select:
    print "Stable"
else:
    print "Not stable" N = int(raw_input()) N int(raw_input()) int raw_input() raw_input line = raw_input() line raw_input() raw_input A = line.strip().split(" ") A line.strip().split(" ") line.strip().split line.strip() line.strip line strip split " " A2 = line.strip().split(" ") A2 line.strip().split(" ") line.strip().split line.strip() line.strip line strip split " " for i in range(0, N):
    min_j = i
    for j in range(i, N):
        if int(A2[j][1:]) < int(A2[min_j][1:]):
            min_j = j
    A2[i], A2[min_j] = A2[min_j], A2[i] i range(0, N) range 0 N min_j = i min_j i for j in range(i, N):
        if int(A2[j][1:]) < int(A2[min_j][1:]):
            min_j = j
     j range(i, N) range i N if int(A2[j][1:]) < int(A2[min_j][1:]):
            min_j = j
     int(A2[j][1:]) < int(A2[min_j][1:]) int(A2[j][1:]) int A2[j][1:] [j] A2 j 1: 1 int(A2[min_j][1:]) int A2[min_j][1:] [min_j] A2 min_j 1: 1 min_j = j min_j j A2[i], A2[min_j] = A2[min_j], A2[i] A2[i] A2 i A2[min_j] A2 min_j A2[min_j] A2 min_j A2[i] A2 i select = " ".join(A2) select " ".join(A2) " ".join " " join A2 flag = True flag True while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if int(A[j][1:]) < int(A[j-1][1:]):
            A[j], A[j-1] = A[j-1], A[j]
            flag = True flag flag = False flag False for j in range(N-1, 0, -1):
        if int(A[j][1:]) < int(A[j-1][1:]):
            A[j], A[j-1] = A[j-1], A[j]
            flag = True j range(N-1, 0, -1) range N-1 N 1 0 -1 if int(A[j][1:]) < int(A[j-1][1:]):
            A[j], A[j-1] = A[j-1], A[j]
            flag = True int(A[j][1:]) < int(A[j-1][1:]) int(A[j][1:]) int A[j][1:] [j] A j 1: 1 int(A[j-1][1:]) int A[j-1][1:] [j-1] A j-1 j 1 1: 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag = True flag True bubble = " ".join(A) bubble " ".join(A) " ".join " " join A print print print if bubble == select:
    print "Stable"
else:
    print "Not stable" bubble == select bubble select print print min_j = i i min_j N = int(raw_input()) int(raw_input()) N min_j = j j min_j select = " ".join(A2) " ".join(A2) select flag = True True flag A2 = line.strip().split(" ") line.strip().split(" ") A2 flag = False False flag line = raw_input() raw_input() line flag = True True flag A = line.strip().split(" ") line.strip().split(" ") A bubble = " ".join(A) " ".join(A) bubble
N = int(raw_input())
line = raw_input()
A = line.strip().split(" ")
A2 = line.strip().split(" ")
for i in range(0, N):
    min_j = i
    for j in range(i, N):
        if int(A2[j][1:]) < int(A2[min_j][1:]):
            min_j = j
    A2[i], A2[min_j] = A2[min_j], A2[i]
select = " ".join(A2)
flag = True
while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if int(A[j][1:]) < int(A[j-1][1:]):
            A[j], A[j-1] = A[j-1], A[j]
            flag = True
bubble = " ".join(A)
print bubble
print "Stable"
print select
if bubble == select:
    print "Stable"
else:
    print "Not stable"