n = int(input())
l = []
for i in input().split():
  t = []
  for j in i: t += [j]
  l += [t]

t = l[:]
f = 0
for i in range(n):
  for j in range(n-1, 0, -1):
    if t[j][1] < t[j-1][1]:
      t[j], t[j-1] = t[j-1], t[j]
    elif t[j][1] == t[j-1][1]:
      f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0
print(*["{0}{1}".format(i[0], i[1]) for i in t])
print("Not stable" if f > 0 else "Stable")

x = l[:]
f = 0
for i in range(n):
  m = i
  for j in range(i, n):
    if x[j][1] < x[m][1]:
      m = j
    elif x[j][1] == x[m][1]:
      f += 1 if l.index(x[m]) > l.index(x[j]) else 0
  x[i], x[m] = x[m], x[i]
print(*["{0}{1}".format(i[0], i[1]) for i in x])
print("Not stable" if f > 0 else "Stable") n = int(input()) n int(input()) int input() input l = [] l [] for i in input().split():
  t = []
  for j in i: t += [j]
  l += [t] i input().split() ().split () input split t = [] t [] for j in i: t += [j]
   j i l += [t] l [t] t t = l[:] t l[:] l : f = 0 f 0 for i in range(n):
  for j in range(n-1, 0, -1):
    if t[j][1] < t[j-1][1]:
      t[j], t[j-1] = t[j-1], t[j]
    elif t[j][1] == t[j-1][1]:
      f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0 i range(n) range n for j in range(n-1, 0, -1):
    if t[j][1] < t[j-1][1]:
      t[j], t[j-1] = t[j-1], t[j]
    elif t[j][1] == t[j-1][1]:
      f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0 j range(n-1, 0, -1) range n-1 n 1 0 -1 if t[j][1] < t[j-1][1]:
      t[j], t[j-1] = t[j-1], t[j]
    elif t[j][1] == t[j-1][1]:
      f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0 t[j][1] < t[j-1][1] t[j][1] [j] t j 1 t[j-1][1] [j-1] t j-1 j 1 1 t[j], t[j-1] = t[j-1], t[j] t[j] t j t[j-1] t j-1 j 1 t[j-1] t j-1 j 1 t[j] t j elif t[j][1] == t[j-1][1]:
      f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0 t[j][1] == t[j-1][1] t[j][1] [j] t j 1 t[j-1][1] [j-1] t j-1 j 1 1 f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0 f 1 if l.index(t[j-1]) > l.index(t[j]) else 0 l.index(t[j-1]) > l.index(t[j]) l.index(t[j-1]) l.index l index t[j-1] t j-1 j 1 l.index(t[j]) l.index l index t[j] t j 1 0 "{0}{1}".format(i[0], i[1]) for i in t for i in t i t for i in t "{0}{1}".format(i[0], i[1]) "{0}{1}".format "{0}{1}" format i[0] i 0 i[1] i 1 print(*["{0}{1}".format(i[0], i[1]) for i in t]) print *["{0}{1}".format(i[0], i[1]) for i in t] ["{0}{1}".format(i[0], i[1]) for i in t] print("Not stable" if f > 0 else "Stable") print "Not stable" if f > 0 else "Stable" f > 0 f 0 "Not stable" "Stable" x = l[:] x l[:] l : f = 0 f 0 for i in range(n):
  m = i
  for j in range(i, n):
    if x[j][1] < x[m][1]:
      m = j
    elif x[j][1] == x[m][1]:
      f += 1 if l.index(x[m]) > l.index(x[j]) else 0
  x[i], x[m] = x[m], x[i] i range(n) range n m = i m i for j in range(i, n):
    if x[j][1] < x[m][1]:
      m = j
    elif x[j][1] == x[m][1]:
      f += 1 if l.index(x[m]) > l.index(x[j]) else 0
   j range(i, n) range i n if x[j][1] < x[m][1]:
      m = j
    elif x[j][1] == x[m][1]:
      f += 1 if l.index(x[m]) > l.index(x[j]) else 0
   x[j][1] < x[m][1] x[j][1] [j] x j 1 x[m][1] [m] x m 1 m = j m j elif x[j][1] == x[m][1]:
      f += 1 if l.index(x[m]) > l.index(x[j]) else 0
   x[j][1] == x[m][1] x[j][1] [j] x j 1 x[m][1] [m] x m 1 f += 1 if l.index(x[m]) > l.index(x[j]) else 0 f 1 if l.index(x[m]) > l.index(x[j]) else 0 l.index(x[m]) > l.index(x[j]) l.index(x[m]) l.index l index x[m] x m l.index(x[j]) l.index l index x[j] x j 1 0 x[i], x[m] = x[m], x[i] x[i] x i x[m] x m x[m] x m x[i] x i "{0}{1}".format(i[0], i[1]) for i in x for i in x i x for i in x "{0}{1}".format(i[0], i[1]) "{0}{1}".format "{0}{1}" format i[0] i 0 i[1] i 1 print(*["{0}{1}".format(i[0], i[1]) for i in x]) print *["{0}{1}".format(i[0], i[1]) for i in x] ["{0}{1}".format(i[0], i[1]) for i in x] print("Not stable" if f > 0 else "Stable") print "Not stable" if f > 0 else "Stable" f > 0 f 0 "Not stable" "Stable" x = l[:] l[:] x n = int(input()) int(input()) n m = j j m t = [] [] t l += [t] [t] l m = i i m f += 1 if l.index(x[m]) > l.index(x[j]) else 0 1 if l.index(x[m]) > l.index(x[j]) else 0 f t = l[:] l[:] t f = 0 0 f f = 0 0 f l = [] [] l f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0 1 if l.index(t[j-1]) > l.index(t[j]) else 0 f
n = int(input())
l = []
for i in input().split():
  t = []
  for j in i: t += [j]
  l += [t]

t = l[:]
f = 0
for i in range(n):
  for j in range(n-1, 0, -1):
    if t[j][1] < t[j-1][1]:
      t[j], t[j-1] = t[j-1], t[j]
    elif t[j][1] == t[j-1][1]:
      f += 1 if l.index(t[j-1]) > l.index(t[j]) else 0
print(*["{0}{1}".format(i[0], i[1]) for i in t])
print("Not stable" if f > 0 else "Stable")

x = l[:]
f = 0
for i in range(n):
  m = i
  for j in range(i, n):
    if x[j][1] < x[m][1]:
      m = j
    elif x[j][1] == x[m][1]:
      f += 1 if l.index(x[m]) > l.index(x[j]) else 0
  x[i], x[m] = x[m], x[i]
print(*["{0}{1}".format(i[0], i[1]) for i in x])
print("Not stable" if f > 0 else "Stable")
