def BubbleSort(C, N):

    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(C1, C2, N):
    if C1 != C2:
        return "Not stable"
    return "Stable"

Num = int(input())
Cards = [x for x in input().split()]
card1 = BubbleSort(list(Cards), Num)
card2 = SelectionSort(list(Cards), Num)

print(" ".join(card1))
print(isStable(card1, card1, Num))
print(" ".join(card2))
print(isStable(card1, card2, Num))
 def BubbleSort(C, N):

    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C BubbleSort for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
     i range(N) range N for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
     j range(N-1, i, -1) range N-1 N 1 i -1 if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
     C[j][1] < C[j-1][1] C[j][1] [j] C j 1 C[j-1][1] [j-1] C j-1 j 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 return C C C C N N def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C SelectionSort for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
     i range(N) range N minj = i minj i for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
         j range(i, N) range i N if C[j][1] < C[minj][1]:
                minj = j
         C[j][1] < C[minj][1] C[j][1] [j] C j 1 C[minj][1] [minj] C minj 1 minj = j minj j C[i], C[minj] = C[minj], C[i] C[i] C i C[minj] C minj C[minj] C minj C[i] C i return C C C C N N def isStable(C1, C2, N):
    if C1 != C2:
        return "Not stable"
    return "Stable" isStable if C1 != C2:
        return "Not stable"
     C1 != C2 C1 C2 return "Not stable" "Not stable" return "Stable" "Stable" C1 C1 C2 C2 N N Num = int(input()) Num int(input()) int input() input x for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() x Cards = [x for x in input().split()] Cards [x for x in input().split()] card1 = BubbleSort(list(Cards), Num) card1 BubbleSort(list(Cards), Num) BubbleSort list(Cards) list Cards Num card2 = SelectionSort(list(Cards), Num) card2 SelectionSort(list(Cards), Num) SelectionSort list(Cards) list Cards Num print(" ".join(card1)) print " ".join(card1) " ".join " " join card1 print(isStable(card1, card1, Num)) print isStable(card1, card1, Num) isStable card1 card1 Num print(" ".join(card2)) print " ".join(card2) " ".join " " join card2 print(isStable(card1, card2, Num)) print isStable(card1, card2, Num) isStable card1 card2 Num Cards = [x for x in input().split()] [x for x in input().split()] Cards def BubbleSort(C, N):

    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C def BubbleSort(C, N):

    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C BubbleSort card2 = SelectionSort(list(Cards), Num) SelectionSort(list(Cards), Num) card2 def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C SelectionSort def isStable(C1, C2, N):
    if C1 != C2:
        return "Not stable"
    return "Stable" def isStable(C1, C2, N):
    if C1 != C2:
        return "Not stable"
    return "Stable" isStable card1 = BubbleSort(list(Cards), Num) BubbleSort(list(Cards), Num) card1 Num = int(input()) int(input()) Num
def BubbleSort(C, N):

    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def isStable(C1, C2, N):
    if C1 != C2:
        return "Not stable"
    return "Stable"

Num = int(input())
Cards = [x for x in input().split()]
card1 = BubbleSort(list(Cards), Num)
card2 = SelectionSort(list(Cards), Num)

print(" ".join(card1))
print(isStable(card1, card1, Num))
print(" ".join(card2))
print(isStable(card1, card2, Num))

