from typing import List


def get_value(card: str) -> int:
    return card[1]


def bublle_sort(C: List[str]) -> None:
    for i in range(len(C)):
        for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j]


def selection_sort(C: List[str]) -> None:
    for i in range(len(C)):
        min_j = i
        for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i]


def is_stable(A_in, A_out) -> bool:
    for i in range(len(A_in)):
        for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
    return True


N = int(input())
C = [str(i) for i in input().split()]
C1 = [i for i in C]
C2 = [i for i in C]

bublle_sort(C1)
print(' '.join(C1))
if is_stable(C, C1):
    print('Stable')
else:
    print('Not stable')

selection_sort(C2)
print(' '.join(C2))
if is_stable(C, C2):
    print('Stable')
else:
    print('Not stable')
 from typing import List def get_value(card: str) -> int:
    return card[1] get_value return card[1] card[1] card 1 card: str card def bublle_sort(C: List[str]) -> None:
    for i in range(len(C)):
        for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j] bublle_sort for i in range(len(C)):
        for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j] i range(len(C)) range len(C) len C for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j] j reversed(range(i + 1, len(C))) reversed range(i + 1, len(C)) range i + 1 i 1 len(C) len C if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j] get_value(C[j]) < get_value(C[j - 1]) get_value(C[j]) get_value C[j] C j get_value(C[j - 1]) get_value C[j - 1] C j - 1 j 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 C: List[str] C def selection_sort(C: List[str]) -> None:
    for i in range(len(C)):
        min_j = i
        for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] selection_sort for i in range(len(C)):
        min_j = i
        for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] i range(len(C)) range len(C) len C min_j = i min_j i for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
         j range(i, len(C)) range i len(C) len C if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
         get_value(C[j]) < get_value(C[min_j]) get_value(C[j]) get_value C[j] C j get_value(C[min_j]) get_value C[min_j] C min_j min_j = j min_j j C[i], C[min_j] = C[min_j], C[i] C[i] C i C[min_j] C min_j C[min_j] C min_j C[i] C i C: List[str] C def is_stable(A_in, A_out) -> bool:
    for i in range(len(A_in)):
        for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
    return True is_stable for i in range(len(A_in)):
        for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
     i range(len(A_in)) range len(A_in) len A_in for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
     j range(i + 1, len(A_in)) range i + 1 i 1 len(A_in) len A_in for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
     a range(len(A_out)) range len(A_out) len A_out for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
     b range(a + 1, len(A_out)) range a + 1 a 1 len(A_out) len A_out if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
     get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a] get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] get_value(A_in[i]) == get_value(A_in[j]) get_value(A_in[i]) get_value A_in[i] A_in i get_value(A_in[j]) get_value A_in[j] A_in j A_in[i] == A_out[b] A_in[i] A_in i A_out[b] A_out b A_in[j] == A_out[a] A_in[j] A_in j A_out[a] A_out a return False False return True True A_in A_in A_out A_out N = int(input()) N int(input()) int input() input str(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() str(i) str i C = [str(i) for i in input().split()] C [str(i) for i in input().split()] i for i in C for i in C i C for i in C i C1 = [i for i in C] C1 [i for i in C] i for i in C for i in C i C for i in C i C2 = [i for i in C] C2 [i for i in C] bublle_sort(C1) bublle_sort C1 print(' '.join(C1)) print ' '.join(C1) ' '.join ' ' join C1 if is_stable(C, C1):
    print('Stable')
else:
    print('Not stable') is_stable(C, C1) is_stable C C1 print('Stable') print 'Stable' print('Not stable') print 'Not stable' selection_sort(C2) selection_sort C2 print(' '.join(C2)) print ' '.join(C2) ' '.join ' ' join C2 if is_stable(C, C2):
    print('Stable')
else:
    print('Not stable') is_stable(C, C2) is_stable C C2 print('Stable') print 'Stable' print('Not stable') print 'Not stable' def is_stable(A_in, A_out) -> bool:
    for i in range(len(A_in)):
        for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
    return True def is_stable(A_in, A_out) -> bool:
    for i in range(len(A_in)):
        for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
    return True is_stable def bublle_sort(C: List[str]) -> None:
    for i in range(len(C)):
        for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j] def bublle_sort(C: List[str]) -> None:
    for i in range(len(C)):
        for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j] bublle_sort def selection_sort(C: List[str]) -> None:
    for i in range(len(C)):
        min_j = i
        for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] def selection_sort(C: List[str]) -> None:
    for i in range(len(C)):
        min_j = i
        for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] selection_sort C = [str(i) for i in input().split()] [str(i) for i in input().split()] C C2 = [i for i in C] [i for i in C] C2 N = int(input()) int(input()) N C1 = [i for i in C] [i for i in C] C1 def get_value(card: str) -> int:
    return card[1] def get_value(card: str) -> int:
    return card[1] get_value
from typing import List


def get_value(card: str) -> int:
    return card[1]


def bublle_sort(C: List[str]) -> None:
    for i in range(len(C)):
        for j in reversed(range(i + 1, len(C))):
            if get_value(C[j]) < get_value(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j]


def selection_sort(C: List[str]) -> None:
    for i in range(len(C)):
        min_j = i
        for j in range(i, len(C)):
            if get_value(C[j]) < get_value(C[min_j]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i]


def is_stable(A_in, A_out) -> bool:
    for i in range(len(A_in)):
        for j in range(i + 1, len(A_in)):
            for a in range(len(A_out)):
                for b in range(a + 1, len(A_out)):
                    if get_value(A_in[i]) == get_value(A_in[j]) and A_in[i] == A_out[b] and A_in[j] == A_out[a]:
                        return False
    return True


N = int(input())
C = [str(i) for i in input().split()]
C1 = [i for i in C]
C2 = [i for i in C]

bublle_sort(C1)
print(' '.join(C1))
if is_stable(C, C1):
    print('Stable')
else:
    print('Not stable')

selection_sort(C2)
print(' '.join(C2))
if is_stable(C, C2):
    print('Stable')
else:
    print('Not stable')

