def BubbleTrump(C, N):
    i = 0
    while i < N:
        j = N - 1
        while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
        i += 1
    return C

def SelectionTrump(C, N):
    i = 0
    while i < N:
        minj = i
        j = i
        while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
        if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
        i += 1
    return C

n = int(input())
C = list(map(str, input().split(' ')))
ans = ''
Cb = BubbleTrump(C.copy(), n)
ans += ' '.join(map(str, Cb)) + '\nStable\n'
Cs = SelectionTrump(C.copy(), n)
q = 0
f = 1
while q < n:
    if Cb[q] != Cs[q]:
        f = 0
    q += 1
ans += ' '.join(map(str, Cs)) + '\n'
if f == 0:
    ans += 'Not stable'
else:
    ans += 'Stable'
print(ans) def BubbleTrump(C, N):
    i = 0
    while i < N:
        j = N - 1
        while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
        i += 1
    return C BubbleTrump i = 0 i 0 while i < N:
        j = N - 1
        while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
        i += 1
     i < N i N j = N - 1 j N - 1 N 1 while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
         j > i j i if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
             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 c = C[j] c C[j] C j C[j] = C[j - 1] C[j] C j C[j - 1] C j - 1 j 1 C[j - 1] = c C[j - 1] C j - 1 j 1 c j -= 1 j 1 i += 1 i 1 return C C C C N N def SelectionTrump(C, N):
    i = 0
    while i < N:
        minj = i
        j = i
        while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
        if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
        i += 1
    return C SelectionTrump i = 0 i 0 while i < N:
        minj = i
        j = i
        while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
        if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
        i += 1
     i < N i N minj = i minj i j = i j i while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
         j < N j 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 j += 1 j 1 if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
         minj != i minj i c = C[i] c C[i] C i C[i] = C[minj] C[i] C i C[minj] C minj C[minj] = c C[minj] C minj c i += 1 i 1 return C C C C N N n = int(input()) n int(input()) int input() input C = list(map(str, input().split(' '))) C list(map(str, input().split(' '))) list map(str, input().split(' ')) map str input().split(' ') ().split () input split ' ' ans = '' ans '' Cb = BubbleTrump(C.copy(), n) Cb BubbleTrump(C.copy(), n) BubbleTrump C.copy() C.copy C copy n ans += ' '.join(map(str, Cb)) + '\nStable\n' ans ' '.join(map(str, Cb)) + '\nStable\n' ' '.join(map(str, Cb)) ' '.join ' ' join map(str, Cb) map str Cb '\nStable\n' Cs = SelectionTrump(C.copy(), n) Cs SelectionTrump(C.copy(), n) SelectionTrump C.copy() C.copy C copy n q = 0 q 0 f = 1 f 1 while q < n:
    if Cb[q] != Cs[q]:
        f = 0
    q += 1 q < n q n if Cb[q] != Cs[q]:
        f = 0
     Cb[q] != Cs[q] Cb[q] Cb q Cs[q] Cs q f = 0 f 0 q += 1 q 1 ans += ' '.join(map(str, Cs)) + '\n' ans ' '.join(map(str, Cs)) + '\n' ' '.join(map(str, Cs)) ' '.join ' ' join map(str, Cs) map str Cs '\n' if f == 0:
    ans += 'Not stable'
else:
    ans += 'Stable' f == 0 f 0 ans += 'Not stable' ans 'Not stable' ans += 'Stable' ans 'Stable' print(ans) print ans ans += ' '.join(map(str, Cb)) + '\nStable\n' ' '.join(map(str, Cb)) + '\nStable\n' ans f = 0 0 f ans = '' '' ans ans += 'Not stable' 'Not stable' ans C = list(map(str, input().split(' '))) list(map(str, input().split(' '))) C ans += ' '.join(map(str, Cs)) + '\n' ' '.join(map(str, Cs)) + '\n' ans n = int(input()) int(input()) n f = 1 1 f q += 1 1 q def BubbleTrump(C, N):
    i = 0
    while i < N:
        j = N - 1
        while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
        i += 1
    return C def BubbleTrump(C, N):
    i = 0
    while i < N:
        j = N - 1
        while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
        i += 1
    return C BubbleTrump Cb = BubbleTrump(C.copy(), n) BubbleTrump(C.copy(), n) Cb Cs = SelectionTrump(C.copy(), n) SelectionTrump(C.copy(), n) Cs q = 0 0 q def SelectionTrump(C, N):
    i = 0
    while i < N:
        minj = i
        j = i
        while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
        if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
        i += 1
    return C def SelectionTrump(C, N):
    i = 0
    while i < N:
        minj = i
        j = i
        while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
        if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
        i += 1
    return C SelectionTrump ans += 'Stable' 'Stable' ans
def BubbleTrump(C, N):
    i = 0
    while i < N:
        j = N - 1
        while j > i:
            if int(C[j][1]) < int(C[j-1][1]):
                c = C[j]
                C[j] = C[j - 1]
                C[j - 1] = c
            j -= 1
        i += 1
    return C

def SelectionTrump(C, N):
    i = 0
    while i < N:
        minj = i
        j = i
        while j < N:
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
            j += 1
        if minj != i:
            c = C[i]
            C[i] = C[minj]
            C[minj] = c
        i += 1
    return C

n = int(input())
C = list(map(str, input().split(' ')))
ans = ''
Cb = BubbleTrump(C.copy(), n)
ans += ' '.join(map(str, Cb)) + '\nStable\n'
Cs = SelectionTrump(C.copy(), n)
q = 0
f = 1
while q < n:
    if Cb[q] != Cs[q]:
        f = 0
    q += 1
ans += ' '.join(map(str, Cs)) + '\n'
if f == 0:
    ans += 'Not stable'
else:
    ans += 'Stable'
print(ans)
