# bable sort
def bubbleSort(o_nums, n):
    nums=o_nums[:]
    for i in range(len(nums)-1):
        for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
    return nums

# selection sort
def selectionSort(o_nums,n):
    nums=o_nums[:]
    for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
        if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
    return nums

n=int(input())
cards=list(input().split())

b=bubbleSort(cards, n)
s=selectionSort(cards,n)
print(*b)
print("Stable")
print(*s)
if bubbleSort(cards, n) == selectionSort(cards, n):
    print("Stable")
else:
    print("Not stable") def bubbleSort(o_nums, n):
    nums=o_nums[:]
    for i in range(len(nums)-1):
        for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
    return nums

# selection sort bubbleSort nums=o_nums[:] nums o_nums[:] o_nums : for i in range(len(nums)-1):
        for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
     i range(len(nums)-1) range len(nums)-1 len(nums) len nums 1 for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
     j range(len(nums)-1,i,-1) range len(nums)-1 len(nums) len nums 1 i -1 if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
     nums[j][1]<nums[j-1][1] nums[j][1] [j] nums j 1 nums[j-1][1] [j-1] nums j-1 j 1 1 nums[j],nums[j-1]=nums[j-1],nums[j] nums[j] nums j nums[j-1] nums j-1 j 1 nums[j-1] nums j-1 j 1 nums[j] nums j return nums nums o_nums o_nums n n def selectionSort(o_nums,n):
    nums=o_nums[:]
    for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
        if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
    return nums selectionSort nums=o_nums[:] nums o_nums[:] o_nums : for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
        if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
     i range(n) range n minj=i minj i for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
         j range(i,n) range i n if nums[j][1]<nums[minj][1]:
                minj=j
         nums[j][1]<nums[minj][1] nums[j][1] [j] nums j 1 nums[minj][1] [minj] nums minj 1 minj=j minj j if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
     nums[i][1]!=nums[minj][1] nums[i][1] [i] nums i 1 nums[minj][1] [minj] nums minj 1 nums[i],nums[minj]=nums[minj],nums[i] nums[i] nums i nums[minj] nums minj nums[minj] nums minj nums[i] nums i return nums nums o_nums o_nums n n n=int(input()) n int(input()) int input() input cards=list(input().split()) cards list(input().split()) list input().split() ().split () input split b=bubbleSort(cards, n) b bubbleSort(cards, n) bubbleSort cards n s=selectionSort(cards,n) s selectionSort(cards,n) selectionSort cards n print(*b) print *b b print("Stable") print "Stable" print(*s) print *s s if bubbleSort(cards, n) == selectionSort(cards, n):
    print("Stable")
else:
    print("Not stable") bubbleSort(cards, n) == selectionSort(cards, n) bubbleSort(cards, n) bubbleSort cards n selectionSort(cards, n) selectionSort cards n print("Stable") print "Stable" print("Not stable") print "Not stable" n=int(input()) int(input()) n cards=list(input().split()) list(input().split()) cards def selectionSort(o_nums,n):
    nums=o_nums[:]
    for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
        if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
    return nums def selectionSort(o_nums,n):
    nums=o_nums[:]
    for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
        if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
    return nums selectionSort def bubbleSort(o_nums, n):
    nums=o_nums[:]
    for i in range(len(nums)-1):
        for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
    return nums

# selection sort def bubbleSort(o_nums, n):
    nums=o_nums[:]
    for i in range(len(nums)-1):
        for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
    return nums

# selection sort bubbleSort s=selectionSort(cards,n) selectionSort(cards,n) s b=bubbleSort(cards, n) bubbleSort(cards, n) b
# bable sort
def bubbleSort(o_nums, n):
    nums=o_nums[:]
    for i in range(len(nums)-1):
        for j in range(len(nums)-1,i,-1):
            if nums[j][1]<nums[j-1][1]:
                nums[j],nums[j-1]=nums[j-1],nums[j]  
    return nums

# selection sort
def selectionSort(o_nums,n):
    nums=o_nums[:]
    for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j][1]<nums[minj][1]:
                minj=j
        if nums[i][1]!=nums[minj][1]:
            nums[i],nums[minj]=nums[minj],nums[i]
    return nums

n=int(input())
cards=list(input().split())

b=bubbleSort(cards, n)
s=selectionSort(cards,n)
print(*b)
print("Stable")
print(*s)
if bubbleSort(cards, n) == selectionSort(cards, n):
    print("Stable")
else:
    print("Not stable")