import copy 

n = int(input())
c = input().split()
c_sel = copy.deepcopy(c)

# check stability of default array
ord_dict_def = {}
for i in range(n) :
    if int(c[i][1]) in ord_dict_def.keys() :
        ord_dict_def[int(c[i][1])] += c[i][0]
    else :
        ord_dict_def[int(c[i][1])] = c[i][0]
        
# do bubble 
for i in range(n) :
    for j in range(n - 1, i, -1) :
        if int(c[j - 1][1]) > int(c[j][1]) :
            c[j - 1], c[j] = c[j], c[j - 1]

# check stability for bubble
ord_dict_bubble = {}

for i in range(n) :
    if int(c[i][1]) in ord_dict_bubble.keys() :
        ord_dict_bubble[int(c[i][1])] += c[i][0]
    else :
        ord_dict_bubble[int(c[i][1])] = c[i][0]
        
# do selection
for i in range(n) :
    cmin = i
    for j in range(i + 1, n) :
        if int(c_sel[j][1]) < int(c_sel[cmin][1]) :
            cmin = j
            
    if i != cmin :
        c_sel[i], c_sel[cmin] = c_sel[cmin], c_sel[i]

# check stability for selection
ord_dict_selection = {}

for i in range(n) :
    if int(c_sel[i][1]) in ord_dict_selection.keys() :
        ord_dict_selection[int(c_sel[i][1])] += c_sel[i][0]
    else :
        ord_dict_selection[int(c_sel[i][1])] = c_sel[i][0]
        
stability_bubble = "Stable"
stability_selection = "Stable"

for i in ord_dict_bubble.keys() :
    if ord_dict_def[i] != ord_dict_bubble[i] :
        stability_bubble = "Not stable"
        
    if ord_dict_def[i] != ord_dict_selection[i] :
        stability_selection = "Not stable"
        
print(" ".join(c))
print(stability_bubble)
print(" ".join(c_sel))
print(stability_selection) import copy copy n = int(input()) n int(input()) int input() input c = input().split() c input().split() ().split () input split c_sel = copy.deepcopy(c) c_sel copy.deepcopy(c) copy.deepcopy copy deepcopy c ord_dict_def = {} ord_dict_def {} for i in range(n) :
    if int(c[i][1]) in ord_dict_def.keys() :
        ord_dict_def[int(c[i][1])] += c[i][0]
    else :
        ord_dict_def[int(c[i][1])] = c[i][0]
        
# do bubble  i range(n) range n if int(c[i][1]) in ord_dict_def.keys() :
        ord_dict_def[int(c[i][1])] += c[i][0]
    else :
        ord_dict_def[int(c[i][1])] = c[i][0]
        
# do bubble  int(c[i][1]) in ord_dict_def.keys() int(c[i][1]) int c[i][1] [i] c i 1 ord_dict_def.keys() ord_dict_def.keys ord_dict_def keys ord_dict_def[int(c[i][1])] += c[i][0] ord_dict_def[int(c[i][1])] ord_dict_def int(c[i][1]) int c[i][1] [i] c i 1 c[i][0] [i] c i 0 ord_dict_def[int(c[i][1])] = c[i][0] ord_dict_def[int(c[i][1])] ord_dict_def int(c[i][1]) int c[i][1] [i] c i 1 c[i][0] [i] c i 0 for i in range(n) :
    for j in range(n - 1, i, -1) :
        if int(c[j - 1][1]) > int(c[j][1]) :
            c[j - 1], c[j] = c[j], c[j - 1]

# check stability for bubble i range(n) range n for j in range(n - 1, i, -1) :
        if int(c[j - 1][1]) > int(c[j][1]) :
            c[j - 1], c[j] = c[j], c[j - 1]

# check stability for bubble j range(n - 1, i, -1) range n - 1 n 1 i -1 if int(c[j - 1][1]) > int(c[j][1]) :
            c[j - 1], c[j] = c[j], c[j - 1]

# check stability for bubble int(c[j - 1][1]) > int(c[j][1]) int(c[j - 1][1]) int c[j - 1][1] [j - 1] c j - 1 j 1 1 int(c[j][1]) int c[j][1] [j] c j 1 c[j - 1], c[j] = c[j], c[j - 1] c[j - 1] c j - 1 j 1 c[j] c j c[j] c j c[j - 1] c j - 1 j 1 ord_dict_bubble = {} ord_dict_bubble {} for i in range(n) :
    if int(c[i][1]) in ord_dict_bubble.keys() :
        ord_dict_bubble[int(c[i][1])] += c[i][0]
    else :
        ord_dict_bubble[int(c[i][1])] = c[i][0]
        
# do selection i range(n) range n if int(c[i][1]) in ord_dict_bubble.keys() :
        ord_dict_bubble[int(c[i][1])] += c[i][0]
    else :
        ord_dict_bubble[int(c[i][1])] = c[i][0]
        
# do selection int(c[i][1]) in ord_dict_bubble.keys() int(c[i][1]) int c[i][1] [i] c i 1 ord_dict_bubble.keys() ord_dict_bubble.keys ord_dict_bubble keys ord_dict_bubble[int(c[i][1])] += c[i][0] ord_dict_bubble[int(c[i][1])] ord_dict_bubble int(c[i][1]) int c[i][1] [i] c i 1 c[i][0] [i] c i 0 ord_dict_bubble[int(c[i][1])] = c[i][0] ord_dict_bubble[int(c[i][1])] ord_dict_bubble int(c[i][1]) int c[i][1] [i] c i 1 c[i][0] [i] c i 0 for i in range(n) :
    cmin = i
    for j in range(i + 1, n) :
        if int(c_sel[j][1]) < int(c_sel[cmin][1]) :
            cmin = j
            
    if i != cmin :
        c_sel[i], c_sel[cmin] = c_sel[cmin], c_sel[i]

# check stability for selection i range(n) range n cmin = i cmin i for j in range(i + 1, n) :
        if int(c_sel[j][1]) < int(c_sel[cmin][1]) :
            cmin = j
            
     j range(i + 1, n) range i + 1 i 1 n if int(c_sel[j][1]) < int(c_sel[cmin][1]) :
            cmin = j
            
     int(c_sel[j][1]) < int(c_sel[cmin][1]) int(c_sel[j][1]) int c_sel[j][1] [j] c_sel j 1 int(c_sel[cmin][1]) int c_sel[cmin][1] [cmin] c_sel cmin 1 cmin = j cmin j if i != cmin :
        c_sel[i], c_sel[cmin] = c_sel[cmin], c_sel[i]

# check stability for selection i != cmin i cmin c_sel[i], c_sel[cmin] = c_sel[cmin], c_sel[i] c_sel[i] c_sel i c_sel[cmin] c_sel cmin c_sel[cmin] c_sel cmin c_sel[i] c_sel i ord_dict_selection = {} ord_dict_selection {} for i in range(n) :
    if int(c_sel[i][1]) in ord_dict_selection.keys() :
        ord_dict_selection[int(c_sel[i][1])] += c_sel[i][0]
    else :
        ord_dict_selection[int(c_sel[i][1])] = c_sel[i][0]
         i range(n) range n if int(c_sel[i][1]) in ord_dict_selection.keys() :
        ord_dict_selection[int(c_sel[i][1])] += c_sel[i][0]
    else :
        ord_dict_selection[int(c_sel[i][1])] = c_sel[i][0]
         int(c_sel[i][1]) in ord_dict_selection.keys() int(c_sel[i][1]) int c_sel[i][1] [i] c_sel i 1 ord_dict_selection.keys() ord_dict_selection.keys ord_dict_selection keys ord_dict_selection[int(c_sel[i][1])] += c_sel[i][0] ord_dict_selection[int(c_sel[i][1])] ord_dict_selection int(c_sel[i][1]) int c_sel[i][1] [i] c_sel i 1 c_sel[i][0] [i] c_sel i 0 ord_dict_selection[int(c_sel[i][1])] = c_sel[i][0] ord_dict_selection[int(c_sel[i][1])] ord_dict_selection int(c_sel[i][1]) int c_sel[i][1] [i] c_sel i 1 c_sel[i][0] [i] c_sel i 0 stability_bubble = "Stable" stability_bubble "Stable" stability_selection = "Stable" stability_selection "Stable" for i in ord_dict_bubble.keys() :
    if ord_dict_def[i] != ord_dict_bubble[i] :
        stability_bubble = "Not stable"
        
    if ord_dict_def[i] != ord_dict_selection[i] :
        stability_selection = "Not stable"
         i ord_dict_bubble.keys() ord_dict_bubble.keys ord_dict_bubble keys if ord_dict_def[i] != ord_dict_bubble[i] :
        stability_bubble = "Not stable"
        
     ord_dict_def[i] != ord_dict_bubble[i] ord_dict_def[i] ord_dict_def i ord_dict_bubble[i] ord_dict_bubble i stability_bubble = "Not stable" stability_bubble "Not stable" if ord_dict_def[i] != ord_dict_selection[i] :
        stability_selection = "Not stable"
         ord_dict_def[i] != ord_dict_selection[i] ord_dict_def[i] ord_dict_def i ord_dict_selection[i] ord_dict_selection i stability_selection = "Not stable" stability_selection "Not stable" print(" ".join(c)) print " ".join(c) " ".join " " join c print(stability_bubble) print stability_bubble print(" ".join(c_sel)) print " ".join(c_sel) " ".join " " join c_sel print(stability_selection) print stability_selection c_sel = copy.deepcopy(c) copy.deepcopy(c) c_sel stability_selection = "Not stable" "Not stable" stability_selection stability_selection = "Stable" "Stable" stability_selection ord_dict_bubble = {} {} ord_dict_bubble stability_bubble = "Not stable" "Not stable" stability_bubble ord_dict_selection = {} {} ord_dict_selection ord_dict_def = {} {} ord_dict_def cmin = i i cmin cmin = j j cmin n = int(input()) int(input()) n stability_bubble = "Stable" "Stable" stability_bubble c = input().split() input().split() c
import copy 

n = int(input())
c = input().split()
c_sel = copy.deepcopy(c)

# check stability of default array
ord_dict_def = {}
for i in range(n) :
    if int(c[i][1]) in ord_dict_def.keys() :
        ord_dict_def[int(c[i][1])] += c[i][0]
    else :
        ord_dict_def[int(c[i][1])] = c[i][0]
        
# do bubble 
for i in range(n) :
    for j in range(n - 1, i, -1) :
        if int(c[j - 1][1]) > int(c[j][1]) :
            c[j - 1], c[j] = c[j], c[j - 1]

# check stability for bubble
ord_dict_bubble = {}

for i in range(n) :
    if int(c[i][1]) in ord_dict_bubble.keys() :
        ord_dict_bubble[int(c[i][1])] += c[i][0]
    else :
        ord_dict_bubble[int(c[i][1])] = c[i][0]
        
# do selection
for i in range(n) :
    cmin = i
    for j in range(i + 1, n) :
        if int(c_sel[j][1]) < int(c_sel[cmin][1]) :
            cmin = j
            
    if i != cmin :
        c_sel[i], c_sel[cmin] = c_sel[cmin], c_sel[i]

# check stability for selection
ord_dict_selection = {}

for i in range(n) :
    if int(c_sel[i][1]) in ord_dict_selection.keys() :
        ord_dict_selection[int(c_sel[i][1])] += c_sel[i][0]
    else :
        ord_dict_selection[int(c_sel[i][1])] = c_sel[i][0]
        
stability_bubble = "Stable"
stability_selection = "Stable"

for i in ord_dict_bubble.keys() :
    if ord_dict_def[i] != ord_dict_bubble[i] :
        stability_bubble = "Not stable"
        
    if ord_dict_def[i] != ord_dict_selection[i] :
        stability_selection = "Not stable"
        
print(" ".join(c))
print(stability_bubble)
print(" ".join(c_sel))
print(stability_selection)
