n = int(input())
s = input()
a = s.split()

def value(a, i):
    return int(a[i][-1])

def isstable(s, a, n):
    for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
    return "Stable"

for i in range(n - 1):
    for j in range(i + 1, n)[::-1]:
        if value(a, j) < value(a, j - 1):
            a[j], a[j - 1] = a[j - 1], a[j]
print(" ".join(a))
print(isstable(s.split(), a, n))

a = s.split()

for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if value(a, j) < value(a, minj):
            minj = j
    a[i], a[minj] = a[minj], a[i]
print(" ".join(a))
print(isstable(s.split(), a, n)) n = int(input()) n int(input()) int input() input s = input() s input() input a = s.split() a s.split() s.split s split def value(a, i):
    return int(a[i][-1]) value return int(a[i][-1]) int(a[i][-1]) int a[i][-1] [i] a i -1 a a i i def isstable(s, a, n):
    for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
    return "Stable" isstable for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
     i range(n - 1) range n - 1 n 1 if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
     value(a, i) == value(a, i + 1) value(a, i) value a i value(a, i + 1) value a i + 1 i 1 v1 = s.index(a[i]) v1 s.index(a[i]) s.index s index a[i] a i v2 = s.index(a[i + 1]) v2 s.index(a[i + 1]) s.index s index a[i + 1] a i + 1 i 1 if v1 > v2:
                return "Not stable"
     v1 > v2 v1 v2 return "Not stable" "Not stable" return "Stable" "Stable" s s a a n n for i in range(n - 1):
    for j in range(i + 1, n)[::-1]:
        if value(a, j) < value(a, j - 1):
            a[j], a[j - 1] = a[j - 1], a[j] i range(n - 1) range n - 1 n 1 for j in range(i + 1, n)[::-1]:
        if value(a, j) < value(a, j - 1):
            a[j], a[j - 1] = a[j - 1], a[j] j range(i + 1, n)[::-1] (i + 1, n) range i + 1 i 1 n ::-1 -1 if value(a, j) < value(a, j - 1):
            a[j], a[j - 1] = a[j - 1], a[j] value(a, j) < value(a, j - 1) value(a, j) value a j value(a, j - 1) value a j - 1 j 1 a[j], a[j - 1] = a[j - 1], a[j] a[j] a j a[j - 1] a j - 1 j 1 a[j - 1] a j - 1 j 1 a[j] a j print(" ".join(a)) print " ".join(a) " ".join " " join a print(isstable(s.split(), a, n)) print isstable(s.split(), a, n) isstable s.split() s.split s split a n a = s.split() a s.split() s.split s split for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if value(a, j) < value(a, minj):
            minj = j
    a[i], a[minj] = a[minj], a[i] i range(n - 1) range n - 1 n 1 minj = i minj i for j in range(i + 1, n):
        if value(a, j) < value(a, minj):
            minj = j
     j range(i + 1, n) range i + 1 i 1 n if value(a, j) < value(a, minj):
            minj = j
     value(a, j) < value(a, minj) value(a, j) value a j value(a, minj) value a minj minj = j minj j a[i], a[minj] = a[minj], a[i] a[i] a i a[minj] a minj a[minj] a minj a[i] a i print(" ".join(a)) print " ".join(a) " ".join " " join a print(isstable(s.split(), a, n)) print isstable(s.split(), a, n) isstable s.split() s.split s split a n def isstable(s, a, n):
    for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
    return "Stable" def isstable(s, a, n):
    for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
    return "Stable" isstable def value(a, i):
    return int(a[i][-1]) def value(a, i):
    return int(a[i][-1]) value minj = j j minj a = s.split() s.split() a minj = i i minj n = int(input()) int(input()) n a = s.split() s.split() a s = input() input() s
n = int(input())
s = input()
a = s.split()

def value(a, i):
    return int(a[i][-1])

def isstable(s, a, n):
    for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
    return "Stable"

for i in range(n - 1):
    for j in range(i + 1, n)[::-1]:
        if value(a, j) < value(a, j - 1):
            a[j], a[j - 1] = a[j - 1], a[j]
print(" ".join(a))
print(isstable(s.split(), a, n))

a = s.split()

for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if value(a, j) < value(a, minj):
            minj = j
    a[i], a[minj] = a[minj], a[i]
print(" ".join(a))
print(isstable(s.split(), a, n))
