input_line = int(input())
out_selection = input().split()
out_bubble = out_selection[:]

# bubblesort                                                                                  
for i in range(input_line):
    for j in range(input_line-1, i, -1):
        if out_bubble[j][1] < out_bubble[j-1][1]:
            out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j]
print(*out_bubble)
print("Stable")

# selectionsort                                                                               
for i in range(input_line):
    minj = i
    for j in range(i, input_line):
        if out_selection[j][1] < out_selection[minj][1]:
            minj = j
    out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i]

print(*out_selection)
print("Stable" if out_bubble == out_selection else "Not stable") input_line = int(input()) input_line int(input()) int input() input out_selection = input().split() out_selection input().split() ().split () input split out_bubble = out_selection[:] out_bubble out_selection[:] out_selection : for i in range(input_line):
    for j in range(input_line-1, i, -1):
        if out_bubble[j][1] < out_bubble[j-1][1]:
            out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j] i range(input_line) range input_line for j in range(input_line-1, i, -1):
        if out_bubble[j][1] < out_bubble[j-1][1]:
            out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j] j range(input_line-1, i, -1) range input_line-1 input_line 1 i -1 if out_bubble[j][1] < out_bubble[j-1][1]:
            out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j] out_bubble[j][1] < out_bubble[j-1][1] out_bubble[j][1] [j] out_bubble j 1 out_bubble[j-1][1] [j-1] out_bubble j-1 j 1 1 out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j] out_bubble[j] out_bubble j out_bubble[j-1] out_bubble j-1 j 1 out_bubble[j-1] out_bubble j-1 j 1 out_bubble[j] out_bubble j print(*out_bubble) print *out_bubble out_bubble print("Stable") print "Stable" for i in range(input_line):
    minj = i
    for j in range(i, input_line):
        if out_selection[j][1] < out_selection[minj][1]:
            minj = j
    out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i] i range(input_line) range input_line minj = i minj i for j in range(i, input_line):
        if out_selection[j][1] < out_selection[minj][1]:
            minj = j
     j range(i, input_line) range i input_line if out_selection[j][1] < out_selection[minj][1]:
            minj = j
     out_selection[j][1] < out_selection[minj][1] out_selection[j][1] [j] out_selection j 1 out_selection[minj][1] [minj] out_selection minj 1 minj = j minj j out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i] out_selection[i] out_selection i out_selection[minj] out_selection minj out_selection[minj] out_selection minj out_selection[i] out_selection i print(*out_selection) print *out_selection out_selection print("Stable" if out_bubble == out_selection else "Not stable") print "Stable" if out_bubble == out_selection else "Not stable" out_bubble == out_selection out_bubble out_selection "Stable" "Not stable" minj = i i minj input_line = int(input()) int(input()) input_line out_selection = input().split() input().split() out_selection out_bubble = out_selection[:] out_selection[:] out_bubble minj = j j minj
input_line = int(input())
out_selection = input().split()
out_bubble = out_selection[:]

# bubblesort                                                                                  
for i in range(input_line):
    for j in range(input_line-1, i, -1):
        if out_bubble[j][1] < out_bubble[j-1][1]:
            out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j]
print(*out_bubble)
print("Stable")

# selectionsort                                                                               
for i in range(input_line):
    minj = i
    for j in range(i, input_line):
        if out_selection[j][1] < out_selection[minj][1]:
            minj = j
    out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i]

print(*out_selection)
print("Stable" if out_bubble == out_selection else "Not stable")
