
N = int(raw_input())
line = raw_input()

num_list1 = line.split()

num_list2 = line.split()


flag = 1
while flag==1:
    flag =0
    for j in range(N-1,0,-1):
        if int(num_list1[j][1:]) < int(num_list1[j-1][1:]):
            a = num_list1[j]
            num_list1[j] = num_list1[j-1]
            num_list1[j-1] = a
           
            flag =1

print " ".join(num_list1)
print "Stable"



for i in range(0,N,1):
   
    minj =i
    for j in range(i,N,1):
        if int(num_list2[j][1:]) < int(num_list2[minj][1:]):
            minj = j
            
    num_list2[i], num_list2[minj] = num_list2[minj], num_list2[i]
print " ".join(num_list2)


if num_list1 == num_list2: 
    print "Stable"
else:
    print "Not stable" N = int(raw_input()) N int(raw_input()) int raw_input() raw_input line = raw_input() line raw_input() raw_input num_list1 = line.split() num_list1 line.split() line.split line split num_list2 = line.split() num_list2 line.split() line.split line split flag = 1 flag 1 while flag==1:
    flag =0
    for j in range(N-1,0,-1):
        if int(num_list1[j][1:]) < int(num_list1[j-1][1:]):
            a = num_list1[j]
            num_list1[j] = num_list1[j-1]
            num_list1[j-1] = a
           
            flag =1 flag==1 flag 1 flag =0 flag 0 for j in range(N-1,0,-1):
        if int(num_list1[j][1:]) < int(num_list1[j-1][1:]):
            a = num_list1[j]
            num_list1[j] = num_list1[j-1]
            num_list1[j-1] = a
           
            flag =1 j range(N-1,0,-1) range N-1 N 1 0 -1 if int(num_list1[j][1:]) < int(num_list1[j-1][1:]):
            a = num_list1[j]
            num_list1[j] = num_list1[j-1]
            num_list1[j-1] = a
           
            flag =1 int(num_list1[j][1:]) < int(num_list1[j-1][1:]) int(num_list1[j][1:]) int num_list1[j][1:] [j] num_list1 j 1: 1 int(num_list1[j-1][1:]) int num_list1[j-1][1:] [j-1] num_list1 j-1 j 1 1: 1 a = num_list1[j] a num_list1[j] num_list1 j num_list1[j] = num_list1[j-1] num_list1[j] num_list1 j num_list1[j-1] num_list1 j-1 j 1 num_list1[j-1] = a num_list1[j-1] num_list1 j-1 j 1 a flag =1 flag 1 print " ".join(num_list1) " ".join " " join num_list1 print for i in range(0,N,1):
   
    minj =i
    for j in range(i,N,1):
        if int(num_list2[j][1:]) < int(num_list2[minj][1:]):
            minj = j
            
    num_list2[i], num_list2[minj] = num_list2[minj], num_list2[i] i range(0,N,1) range 0 N 1 minj =i minj i for j in range(i,N,1):
        if int(num_list2[j][1:]) < int(num_list2[minj][1:]):
            minj = j
            
     j range(i,N,1) range i N 1 if int(num_list2[j][1:]) < int(num_list2[minj][1:]):
            minj = j
            
     int(num_list2[j][1:]) < int(num_list2[minj][1:]) int(num_list2[j][1:]) int num_list2[j][1:] [j] num_list2 j 1: 1 int(num_list2[minj][1:]) int num_list2[minj][1:] [minj] num_list2 minj 1: 1 minj = j minj j num_list2[i], num_list2[minj] = num_list2[minj], num_list2[i] num_list2[i] num_list2 i num_list2[minj] num_list2 minj num_list2[minj] num_list2 minj num_list2[i] num_list2 i print " ".join(num_list2) " ".join " " join num_list2 if num_list1 == num_list2: 
    print "Stable"
else:
    print "Not stable" num_list1 == num_list2 num_list1 num_list2 print print minj = j j minj line = raw_input() raw_input() line N = int(raw_input()) int(raw_input()) N num_list2 = line.split() line.split() num_list2 flag = 1 1 flag num_list1 = line.split() line.split() num_list1 flag =0 0 flag flag =1 1 flag minj =i i minj a = num_list1[j] num_list1[j] a

N = int(raw_input())
line = raw_input()

num_list1 = line.split()

num_list2 = line.split()


flag = 1
while flag==1:
    flag =0
    for j in range(N-1,0,-1):
        if int(num_list1[j][1:]) < int(num_list1[j-1][1:]):
            a = num_list1[j]
            num_list1[j] = num_list1[j-1]
            num_list1[j-1] = a
           
            flag =1

print " ".join(num_list1)
print "Stable"



for i in range(0,N,1):
   
    minj =i
    for j in range(i,N,1):
        if int(num_list2[j][1:]) < int(num_list2[minj][1:]):
            minj = j
            
    num_list2[i], num_list2[minj] = num_list2[minj], num_list2[i]
print " ".join(num_list2)


if num_list1 == num_list2: 
    print "Stable"
else:
    print "Not stable"