def compare_cards(a, b):
    return a[1] < b[1]

def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j]

def selection(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i]

def check_stable(originC, sortedC):
    for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
    return 'Stable'

        
N = int(input())
C = input().split()

bubbleC = list(C)
selectionC = list(C)

bubble(bubbleC)
selection(selectionC)

print(*bubbleC)
print(check_stable(C, bubbleC))
print(*selectionC)
print(check_stable(C, selectionC)) def compare_cards(a, b):
    return a[1] < b[1] compare_cards return a[1] < b[1] a[1] < b[1] a[1] a 1 b[1] b 1 a a b b def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j] bubble for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], 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 range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j] j range(len(C) - 1, i, -1) range len(C) - 1 len(C) len C 1 i -1 if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j] compare_cards(C[j], C[j - 1]) compare_cards C[j] C j 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 C def selection(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i] selection for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i] i range(len(C)) range len(C) len C mini = i mini i for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
         j range(i, len(C)) range i len(C) len C if compare_cards(C[j], C[mini]):
                mini = j
         compare_cards(C[j], C[mini]) compare_cards C[j] C j C[mini] C mini mini = j mini j C[i], C[mini] = C[mini], C[i] C[i] C i C[mini] C mini C[mini] C mini C[i] C i C C def check_stable(originC, sortedC):
    for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
    return 'Stable'

         check_stable for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
     i range(len(originC) - 1) range len(originC) - 1 len(originC) len originC 1 if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
     not compare_cards(sortedC[i], sortedC[i + 1]) compare_cards(sortedC[i], sortedC[i + 1]) compare_cards sortedC[i] sortedC i sortedC[i + 1] sortedC i + 1 i 1 if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
     originC.index(sortedC[i]) > originC.index(sortedC[i + 1]) originC.index(sortedC[i]) originC.index originC index sortedC[i] sortedC i originC.index(sortedC[i + 1]) originC.index originC index sortedC[i + 1] sortedC i + 1 i 1 return 'Not stable' 'Not stable' return 'Stable' 'Stable' originC originC sortedC sortedC N = int(input()) N int(input()) int input() input C = input().split() C input().split() ().split () input split bubbleC = list(C) bubbleC list(C) list C selectionC = list(C) selectionC list(C) list C bubble(bubbleC) bubble bubbleC selection(selectionC) selection selectionC print(*bubbleC) print *bubbleC bubbleC print(check_stable(C, bubbleC)) print check_stable(C, bubbleC) check_stable C bubbleC print(*selectionC) print *selectionC selectionC print(check_stable(C, selectionC)) print check_stable(C, selectionC) check_stable C selectionC C = input().split() input().split() C def selection(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i] def selection(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i] selection def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j] def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j] bubble bubbleC = list(C) list(C) bubbleC def compare_cards(a, b):
    return a[1] < b[1] def compare_cards(a, b):
    return a[1] < b[1] compare_cards selectionC = list(C) list(C) selectionC def check_stable(originC, sortedC):
    for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
    return 'Stable'

         def check_stable(originC, sortedC):
    for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
    return 'Stable'

         check_stable N = int(input()) int(input()) N
def compare_cards(a, b):
    return a[1] < b[1]

def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j]

def selection(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i]

def check_stable(originC, sortedC):
    for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
    return 'Stable'

        
N = int(input())
C = input().split()

bubbleC = list(C)
selectionC = list(C)

bubble(bubbleC)
selection(selectionC)

print(*bubbleC)
print(check_stable(C, bubbleC))
print(*selectionC)
print(check_stable(C, selectionC))