def is_stable(output_str, same_num_str):
    if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
    return "Stable"
    
data_num = int(input())
cards = input().split(" ")
cards2 = cards[:]
cnt = 0
num_1 = 0
num_2 = 0
same_num_str = []
output_str = ""
judge_stbl = ""
for i in range(data_num):
    
    for j in range(data_num-1, i,-1):
        if int(cards[j][1:]) < int(cards[j-1][1:]):
            cards[j], cards[j-1] = cards[j-1], cards[j]
        elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
            
output_str = " ".join(cards) 
judge_stbl = is_stable(output_str, same_num_str)

print(output_str + "\n" + judge_stbl)

same_num_str = []
output_str = ""
judge_stbl = ""

for i in range(data_num):
    min_idx = i
    for j in range(i, data_num):
        if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
            min_idx = j
        elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

    if i != min_idx:
        cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i]

output_str = " ".join(cards2) 
judge_stbl = is_stable(output_str, same_num_str)

print(output_str + "\n" + judge_stbl) def is_stable(output_str, same_num_str):
    if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
    return "Stable"
     is_stable if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
     len(same_num_str)>0 len(same_num_str) len same_num_str 0 for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
     i range(len(same_num_str)) range len(same_num_str) len same_num_str if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
     output_str.find(same_num_str[i]) == -1 output_str.find(same_num_str[i]) output_str.find output_str find same_num_str[i] same_num_str i -1 return "Not stable" "Not stable" return "Stable" "Stable" output_str output_str same_num_str same_num_str data_num = int(input()) data_num int(input()) int input() input cards = input().split(" ") cards input().split(" ") ().split () input split " " cards2 = cards[:] cards2 cards[:] cards : cnt = 0 cnt 0 num_1 = 0 num_1 0 num_2 = 0 num_2 0 same_num_str = [] same_num_str [] output_str = "" output_str "" judge_stbl = "" judge_stbl "" for i in range(data_num):
    
    for j in range(data_num-1, i,-1):
        if int(cards[j][1:]) < int(cards[j-1][1:]):
            cards[j], cards[j-1] = cards[j-1], cards[j]
        elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
             i range(data_num) range data_num for j in range(data_num-1, i,-1):
        if int(cards[j][1:]) < int(cards[j-1][1:]):
            cards[j], cards[j-1] = cards[j-1], cards[j]
        elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
             j range(data_num-1, i,-1) range data_num-1 data_num 1 i -1 if int(cards[j][1:]) < int(cards[j-1][1:]):
            cards[j], cards[j-1] = cards[j-1], cards[j]
        elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
             int(cards[j][1:]) < int(cards[j-1][1:]) int(cards[j][1:]) int cards[j][1:] [j] cards j 1: 1 int(cards[j-1][1:]) int cards[j-1][1:] [j-1] cards j-1 j 1 1: 1 cards[j], cards[j-1] = cards[j-1], cards[j] cards[j] cards j cards[j-1] cards j-1 j 1 cards[j-1] cards j-1 j 1 cards[j] cards j elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
             int(cards[j][1:]) == int(cards[j-1][1:]) int(cards[j][1:]) int cards[j][1:] [j] cards j 1: 1 int(cards[j-1][1:]) int cards[j-1][1:] [j-1] cards j-1 j 1 1: 1 same_num_str.append(cards[j-1]+" "+cards[j]) same_num_str.append same_num_str append cards[j-1]+" "+cards[j] cards[j-1]+" " cards[j-1] cards j-1 j 1 " " cards[j] cards j output_str = " ".join(cards) output_str " ".join(cards) " ".join " " join cards judge_stbl = is_stable(output_str, same_num_str) judge_stbl is_stable(output_str, same_num_str) is_stable output_str same_num_str print(output_str + "\n" + judge_stbl) print output_str + "\n" + judge_stbl output_str + "\n" output_str "\n" judge_stbl same_num_str = [] same_num_str [] output_str = "" output_str "" judge_stbl = "" judge_stbl "" for i in range(data_num):
    min_idx = i
    for j in range(i, data_num):
        if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
            min_idx = j
        elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

    if i != min_idx:
        cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i] i range(data_num) range data_num min_idx = i min_idx i for j in range(i, data_num):
        if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
            min_idx = j
        elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

     j range(i, data_num) range i data_num if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
            min_idx = j
        elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

     int(cards2[j][1:]) < int(cards2[min_idx][1:]) int(cards2[j][1:]) int cards2[j][1:] [j] cards2 j 1: 1 int(cards2[min_idx][1:]) int cards2[min_idx][1:] [min_idx] cards2 min_idx 1: 1 min_idx = j min_idx j elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

     int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx int(cards2[j][1:]) == int(cards2[min_idx][1:]) int(cards2[j][1:]) int cards2[j][1:] [j] cards2 j 1: 1 int(cards2[min_idx][1:]) int cards2[min_idx][1:] [min_idx] cards2 min_idx 1: 1 j != min_idx j min_idx same_num_str.append(cards2[min_idx]+" "+cards2[j]) same_num_str.append same_num_str append cards2[min_idx]+" "+cards2[j] cards2[min_idx]+" " cards2[min_idx] cards2 min_idx " " cards2[j] cards2 j if i != min_idx:
        cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i] i != min_idx i min_idx cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i] cards2[i] cards2 i cards2[min_idx] cards2 min_idx cards2[min_idx] cards2 min_idx cards2[i] cards2 i output_str = " ".join(cards2) output_str " ".join(cards2) " ".join " " join cards2 judge_stbl = is_stable(output_str, same_num_str) judge_stbl is_stable(output_str, same_num_str) is_stable output_str same_num_str print(output_str + "\n" + judge_stbl) print output_str + "\n" + judge_stbl output_str + "\n" output_str "\n" judge_stbl min_idx = j j min_idx cnt = 0 0 cnt output_str = " ".join(cards2) " ".join(cards2) output_str output_str = "" "" output_str output_str = "" "" output_str min_idx = i i min_idx judge_stbl = "" "" judge_stbl judge_stbl = "" "" judge_stbl output_str = " ".join(cards) " ".join(cards) output_str num_1 = 0 0 num_1 judge_stbl = is_stable(output_str, same_num_str) is_stable(output_str, same_num_str) judge_stbl num_2 = 0 0 num_2 same_num_str = [] [] same_num_str judge_stbl = is_stable(output_str, same_num_str) is_stable(output_str, same_num_str) judge_stbl cards2 = cards[:] cards[:] cards2 cards = input().split(" ") input().split(" ") cards same_num_str = [] [] same_num_str def is_stable(output_str, same_num_str):
    if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
    return "Stable"
     def is_stable(output_str, same_num_str):
    if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
    return "Stable"
     is_stable data_num = int(input()) int(input()) data_num
def is_stable(output_str, same_num_str):
    if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not stable"
    return "Stable"
    
data_num = int(input())
cards = input().split(" ")
cards2 = cards[:]
cnt = 0
num_1 = 0
num_2 = 0
same_num_str = []
output_str = ""
judge_stbl = ""
for i in range(data_num):
    
    for j in range(data_num-1, i,-1):
        if int(cards[j][1:]) < int(cards[j-1][1:]):
            cards[j], cards[j-1] = cards[j-1], cards[j]
        elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
            
output_str = " ".join(cards) 
judge_stbl = is_stable(output_str, same_num_str)

print(output_str + "\n" + judge_stbl)

same_num_str = []
output_str = ""
judge_stbl = ""

for i in range(data_num):
    min_idx = i
    for j in range(i, data_num):
        if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
            min_idx = j
        elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

    if i != min_idx:
        cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i]

output_str = " ".join(cards2) 
judge_stbl = is_stable(output_str, same_num_str)

print(output_str + "\n" + judge_stbl)