n = int(input())
*s1, = input().split()
s2 = s1[:]

def bubbleSort(s):
    flag = True
    while flag:
        flag = False
        for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
    return s

def selectionSort(s):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
        s[i],s[minj] = s[minj],s[i]
    return s

print(' '.join(bubbleSort(s1)))
print("Stable")
print(' '.join(selectionSort(s2)))
if s1 == s2:
    print("Stable")
else:
    print("Not stable")
 n = int(input()) n int(input()) int input() input *s1, = input().split() *s1 s1 input().split() ().split () input split s2 = s1[:] s2 s1[:] s1 : def bubbleSort(s):
    flag = True
    while flag:
        flag = False
        for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
    return s bubbleSort flag = True flag True while flag:
        flag = False
        for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
     flag flag = False flag False for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
     i range(n-1) range n-1 n 1 if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
     int(s[i][1]) > int(s[i+1][1]) int(s[i][1]) int s[i][1] [i] s i 1 int(s[i+1][1]) int s[i+1][1] [i+1] s i+1 i 1 1 s[i],s[i+1] = s[i+1],s[i] s[i] s i s[i+1] s i+1 i 1 s[i+1] s i+1 i 1 s[i] s i flag = True flag True return s s s s def selectionSort(s):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
        s[i],s[minj] = s[minj],s[i]
    return s selectionSort for i in range(n):
        minj = i
        for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
        s[i],s[minj] = s[minj],s[i]
     i range(n) range n minj = i minj i for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
         j range(i+1,n) range i+1 i 1 n if int(s[minj][1]) > int(s[j][1]):
                minj = j
         int(s[minj][1]) > int(s[j][1]) int(s[minj][1]) int s[minj][1] [minj] s minj 1 int(s[j][1]) int s[j][1] [j] s j 1 minj = j minj j s[i],s[minj] = s[minj],s[i] s[i] s i s[minj] s minj s[minj] s minj s[i] s i return s s s s print(' '.join(bubbleSort(s1))) print ' '.join(bubbleSort(s1)) ' '.join ' ' join bubbleSort(s1) bubbleSort s1 print("Stable") print "Stable" print(' '.join(selectionSort(s2))) print ' '.join(selectionSort(s2)) ' '.join ' ' join selectionSort(s2) selectionSort s2 if s1 == s2:
    print("Stable")
else:
    print("Not stable") s1 == s2 s1 s2 print("Stable") print "Stable" print("Not stable") print "Not stable" s2 = s1[:] s1[:] s2 def selectionSort(s):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
        s[i],s[minj] = s[minj],s[i]
    return s def selectionSort(s):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
        s[i],s[minj] = s[minj],s[i]
    return s selectionSort n = int(input()) int(input()) n def bubbleSort(s):
    flag = True
    while flag:
        flag = False
        for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
    return s def bubbleSort(s):
    flag = True
    while flag:
        flag = False
        for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
    return s bubbleSort
n = int(input())
*s1, = input().split()
s2 = s1[:]

def bubbleSort(s):
    flag = True
    while flag:
        flag = False
        for i in range(n-1):
            if int(s[i][1]) > int(s[i+1][1]):
                s[i],s[i+1] = s[i+1],s[i]
                flag = True
    return s

def selectionSort(s):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if int(s[minj][1]) > int(s[j][1]):
                minj = j
        s[i],s[minj] = s[minj],s[i]
    return s

print(' '.join(bubbleSort(s1)))
print("Stable")
print(' '.join(selectionSort(s2)))
if s1 == s2:
    print("Stable")
else:
    print("Not stable")

