N, C = int(input()), [temp for temp in input().split()]
D    = list(C)

for i in range(N) :
    for j in range(i + 1, N)[ : : -1] :
        if int(C[j][1 :]) < int(C[j - 1][1 :]) :
            C[j], C[j - 1] = C[j - 1], C[j]
print(*C)
print('Stable')

for i in range(N) :
    minj = i
    for j in range(i, N) :
        if int(D[j][1 :]) < int(D[minj][1 :]) :
            minj = j
    D[i], D[minj] = D[minj], D[i]
print(*D)

cou = 0
for che in range(N) :
    if C[che] != D[che] :
        cou = 1
if cou == 0 : print('Stable')
else        : print('Not stable') temp for temp in input().split() for temp in input().split() temp input().split() ().split () input split for temp in input().split() temp N, C = int(input()), [temp for temp in input().split()] N int(input()) int input() input C [temp for temp in input().split()] D    = list(C) D list(C) list C for i in range(N) :
    for j in range(i + 1, N)[ : : -1] :
        if int(C[j][1 :]) < int(C[j - 1][1 :]) :
            C[j], C[j - 1] = C[j - 1], C[j] i range(N) range N for j in range(i + 1, N)[ : : -1] :
        if int(C[j][1 :]) < int(C[j - 1][1 :]) :
            C[j], C[j - 1] = C[j - 1], C[j] j range(i + 1, N)[ : : -1] (i + 1, N) range i + 1 i 1 N : : -1 -1 if int(C[j][1 :]) < int(C[j - 1][1 :]) :
            C[j], C[j - 1] = C[j - 1], C[j] int(C[j][1 :]) < int(C[j - 1][1 :]) int(C[j][1 :]) int C[j][1 :] [j] C j 1 : 1 int(C[j - 1][1 :]) int C[j - 1][1 :] [j - 1] C j - 1 j 1 1 : 1 C[j], C[j - 1] = C[j - 1], C[j] C[j] C j C[j - 1] C j - 1 j 1 C[j - 1] C j - 1 j 1 C[j] C j print(*C) print *C C print('Stable') print 'Stable' for i in range(N) :
    minj = i
    for j in range(i, N) :
        if int(D[j][1 :]) < int(D[minj][1 :]) :
            minj = j
    D[i], D[minj] = D[minj], D[i] i range(N) range 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 : 1 int(D[minj][1 :]) int D[minj][1 :] [minj] D minj 1 : 1 minj = j minj j D[i], D[minj] = D[minj], D[i] D[i] D i D[minj] D minj D[minj] D minj D[i] D i print(*D) print *D D cou = 0 cou 0 for che in range(N) :
    if C[che] != D[che] :
        cou = 1 che range(N) range N if C[che] != D[che] :
        cou = 1 C[che] != D[che] C[che] C che D[che] D che cou = 1 cou 1 if cou == 0 : print('Stable')
else        : print('Not stable') cou == 0 cou 0 cou = 0 0 cou minj = i i minj minj = j j minj N, C = int(input()), [temp for temp in input().split()] int(input()) N D    = list(C) list(C) D cou = 1 1 cou C = int(input()), [temp for temp in input().split()] [temp for temp in input().split()] C
N, C = int(input()), [temp for temp in input().split()]
D    = list(C)

for i in range(N) :
    for j in range(i + 1, N)[ : : -1] :
        if int(C[j][1 :]) < int(C[j - 1][1 :]) :
            C[j], C[j - 1] = C[j - 1], C[j]
print(*C)
print('Stable')

for i in range(N) :
    minj = i
    for j in range(i, N) :
        if int(D[j][1 :]) < int(D[minj][1 :]) :
            minj = j
    D[i], D[minj] = D[minj], D[i]
print(*D)

cou = 0
for che in range(N) :
    if C[che] != D[che] :
        cou = 1
if cou == 0 : print('Stable')
else        : print('Not stable')