# coding: utf-8
# Here your code !
n=int(input())
cards=input().split()

def bubble_sort(cards_b,n):
    for i in range(n):
        for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
    return cards_b

def selection_sort(cards_s,n):
    for i in range(n):
        minv=i
        for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
        cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
    return cards_s


dummy=cards.copy()
ans_1=bubble_sort(cards,n)

ans_2=selection_sort(dummy,n)

print(*ans_1)
print("Stable")
print(*ans_2)
if ans_1!=ans_2:
    print("Not stable")
else:
    print("Stable") n=int(input()) n int(input()) int input() input cards=input().split() cards input().split() ().split () input split def bubble_sort(cards_b,n):
    for i in range(n):
        for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
    return cards_b bubble_sort for i in range(n):
        for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
     i range(n) range n for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
     j range(-1,-n,-1) range -1 -n n -1 a=int(cards_b[j][1]) a int(cards_b[j][1]) int cards_b[j][1] [j] cards_b j 1 b=int(cards_b[j-1][1]) b int(cards_b[j-1][1]) int cards_b[j-1][1] [j-1] cards_b j-1 j 1 1 if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
     a<b a b cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j] cards_b[j] cards_b j cards_b[j-1] cards_b j-1 j 1 cards_b[j-1] cards_b j-1 j 1 cards_b[j] cards_b j return cards_b cards_b cards_b cards_b n n def selection_sort(cards_s,n):
    for i in range(n):
        minv=i
        for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
        cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
    return cards_s selection_sort for i in range(n):
        minv=i
        for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
        cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
     i range(n) range n minv=i minv i for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
         j range(i,n) range i n a=int(cards_s[minv][1]) a int(cards_s[minv][1]) int cards_s[minv][1] [minv] cards_s minv 1 b=int(cards_s[j][1]) b int(cards_s[j][1]) int cards_s[j][1] [j] cards_s j 1 if a>b:
                minv=j
         a>b a b minv=j minv j cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv] cards_s[minv] cards_s minv cards_s[i] cards_s i cards_s[i] cards_s i cards_s[minv] cards_s minv return cards_s cards_s cards_s cards_s n n dummy=cards.copy() dummy cards.copy() cards.copy cards copy ans_1=bubble_sort(cards,n) ans_1 bubble_sort(cards,n) bubble_sort cards n ans_2=selection_sort(dummy,n) ans_2 selection_sort(dummy,n) selection_sort dummy n print(*ans_1) print *ans_1 ans_1 print("Stable") print "Stable" print(*ans_2) print *ans_2 ans_2 if ans_1!=ans_2:
    print("Not stable")
else:
    print("Stable") ans_1!=ans_2 ans_1 ans_2 print("Not stable") print "Not stable" print("Stable") print "Stable" cards=input().split() input().split() cards n=int(input()) int(input()) n def selection_sort(cards_s,n):
    for i in range(n):
        minv=i
        for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
        cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
    return cards_s def selection_sort(cards_s,n):
    for i in range(n):
        minv=i
        for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
        cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
    return cards_s selection_sort def bubble_sort(cards_b,n):
    for i in range(n):
        for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
    return cards_b def bubble_sort(cards_b,n):
    for i in range(n):
        for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
    return cards_b bubble_sort ans_1=bubble_sort(cards,n) bubble_sort(cards,n) ans_1 dummy=cards.copy() cards.copy() dummy ans_2=selection_sort(dummy,n) selection_sort(dummy,n) ans_2
# coding: utf-8
# Here your code !
n=int(input())
cards=input().split()

def bubble_sort(cards_b,n):
    for i in range(n):
        for j in range(-1,-n,-1):
            a=int(cards_b[j][1])
            b=int(cards_b[j-1][1])
            if a<b:
                cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
    return cards_b

def selection_sort(cards_s,n):
    for i in range(n):
        minv=i
        for j in range(i,n):
            a=int(cards_s[minv][1])
            b=int(cards_s[j][1])
            if a>b:
                minv=j
        cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
    return cards_s


dummy=cards.copy()
ans_1=bubble_sort(cards,n)

ans_2=selection_sort(dummy,n)

print(*ans_1)
print("Stable")
print(*ans_2)
if ans_1!=ans_2:
    print("Not stable")
else:
    print("Stable")