def bubbleSort(c):
    for i in range(0, len(c) - 1):
        for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]


def selectionSort(c):
    for i in range(0, len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]


def isStable(c1, c2):
    for i in range(0, len(c1)):
        if c1[i][0] != c2[i][0]:
            return False
    return True


import copy
n = int(input())
c1 = input().split()
c2 = copy.copy(c1)

bubbleSort(c1)
selectionSort(c2)
print(*c1)
print("Stable")
print(*c2)
print("Stable") if isStable(c1, c2) else print("Not stable")
 def bubbleSort(c):
    for i in range(0, len(c) - 1):
        for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j] bubbleSort for i in range(0, len(c) - 1):
        for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j] i range(0, len(c) - 1) range 0 len(c) - 1 len(c) len c 1 for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][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 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 c c def selectionSort(c):
    for i in range(0, len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i] selectionSort for i in range(0, len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i] i range(0, len(c)) range 0 len(c) len c minj = i minj i for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
         j range(i, len(c)) range i len(c) len c 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 c c def isStable(c1, c2):
    for i in range(0, len(c1)):
        if c1[i][0] != c2[i][0]:
            return False
    return True isStable for i in range(0, len(c1)):
        if c1[i][0] != c2[i][0]:
            return False
     i range(0, len(c1)) range 0 len(c1) len c1 if c1[i][0] != c2[i][0]:
            return False
     c1[i][0] != c2[i][0] c1[i][0] [i] c1 i 0 c2[i][0] [i] c2 i 0 return False False return True True c1 c1 c2 c2 import copy copy n = int(input()) n int(input()) int input() input c1 = input().split() c1 input().split() ().split () input split c2 = copy.copy(c1) c2 copy.copy(c1) copy.copy copy copy c1 bubbleSort(c1) bubbleSort c1 selectionSort(c2) selectionSort c2 print(*c1) print *c1 c1 print("Stable") print "Stable" print(*c2) print *c2 c2 print("Stable") if isStable(c1, c2) else print("Not stable") isStable(c1, c2) isStable c1 c2 print("Stable") print "Stable" print("Not stable") print "Not stable" n = int(input()) int(input()) n def isStable(c1, c2):
    for i in range(0, len(c1)):
        if c1[i][0] != c2[i][0]:
            return False
    return True def isStable(c1, c2):
    for i in range(0, len(c1)):
        if c1[i][0] != c2[i][0]:
            return False
    return True isStable def bubbleSort(c):
    for i in range(0, len(c) - 1):
        for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j] def bubbleSort(c):
    for i in range(0, len(c) - 1):
        for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j] bubbleSort c1 = input().split() input().split() c1 c2 = copy.copy(c1) copy.copy(c1) c2 def selectionSort(c):
    for i in range(0, len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i] def selectionSort(c):
    for i in range(0, len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i] selectionSort
def bubbleSort(c):
    for i in range(0, len(c) - 1):
        for j in range(len(c)-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]


def selectionSort(c):
    for i in range(0, len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]


def isStable(c1, c2):
    for i in range(0, len(c1)):
        if c1[i][0] != c2[i][0]:
            return False
    return True


import copy
n = int(input())
c1 = input().split()
c2 = copy.copy(c1)

bubbleSort(c1)
selectionSort(c2)
print(*c1)
print("Stable")
print(*c2)
print("Stable") if isStable(c1, c2) else print("Not stable")

