n=int(input())
r=input().split()

def BubbleSort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(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):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c

l=list(r)
a=BubbleSort(l, n)
print(*a)
print('Stable')
l=list(r)
b=SelectionSort(l, n)
print(*b)
if a==b:
    print('Stable')
else:
    print('Not stable') n=int(input()) n int(input()) int input() input r=input().split() r input().split() ().split () input split def BubbleSort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(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 int(c[j][-1]) < int(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 int(c[j][-1]) < int(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 int(c[j][-1]) < int(c[j-1][-1]):
                c[j], c[j-1]=c[j-1],c[j]
     int(c[j][-1]) < int(c[j-1][-1]) int(c[j][-1]) int c[j][-1] [j] c j -1 int(c[j-1][-1]) int 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):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c SelectionSort for i in range(n):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
     i range(n) range n m=i m i for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
         j range(i, n) range i n if int(c[j][-1]) < int(c[m][-1]):
                m=j
         int(c[j][-1]) < int(c[m][-1]) int(c[j][-1]) int c[j][-1] [j] c j -1 int(c[m][-1]) int c[m][-1] [m] c m -1 m=j m j c[i],c[m]=c[m],c[i] c[i] c i c[m] c m c[m] c m c[i] c i return c c c c n n l=list(r) l list(r) list r a=BubbleSort(l, n) a BubbleSort(l, n) BubbleSort l n print(*a) print *a a print('Stable') print 'Stable' l=list(r) l list(r) list r b=SelectionSort(l, n) b SelectionSort(l, n) SelectionSort l n print(*b) print *b b if a==b:
    print('Stable')
else:
    print('Not stable') a==b a b print('Stable') print 'Stable' print('Not stable') print 'Not stable' a=BubbleSort(l, n) BubbleSort(l, n) a r=input().split() input().split() r l=list(r) list(r) l l=list(r) list(r) l def BubbleSort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(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 int(c[j][-1]) < int(c[j-1][-1]):
                c[j], c[j-1]=c[j-1],c[j]
    return c BubbleSort n=int(input()) int(input()) n def SelectionSort(c, n):
    for i in range(n):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c def SelectionSort(c, n):
    for i in range(n):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c SelectionSort b=SelectionSort(l, n) SelectionSort(l, n) b
n=int(input())
r=input().split()

def BubbleSort(c, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][-1]) < int(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):
        m=i
        for j in range(i, n):
            if int(c[j][-1]) < int(c[m][-1]):
                m=j
        c[i],c[m]=c[m],c[i]
    return c

l=list(r)
a=BubbleSort(l, n)
print(*a)
print('Stable')
l=list(r)
b=SelectionSort(l, n)
print(*b)
if a==b:
    print('Stable')
else:
    print('Not stable')
