#!/bin/python3 import sys def minimumZooNumbers(num_zoo, num_animals, types, sources, dests): sorted_dests = sorted(dests) answers = [-1 for x in range(num_animals)] #print(types) for t in range(len(types)): types[t] = 'EC' if types[t]=='E' or types[t]=='C' else 'DM' #print("new_types",types) for i in range(1,num_animals+1): if i == 1: answers[i-1] = sorted_dests[i-1] if i == 3: loaded_1 = [0 for x in range(num_zoo)] loaded_2 = [0 for x in range(num_zoo)] loaded_3 = [0 for x in range(num_zoo)] min_d_1 = sorted_dests[i-3] min_d_2 = sorted_dests[i-2] min_d_3 = sorted_dests[i-1] print("min_d",min_d_1,min_d_2,min_d_3) index_1 = dests.index(min_d_1) if min_d_2 == min_d_1: index_2 = dests.index(min_d_2, index_1 + 1) else: index_2 = dests.index(min_d_2) if min_d_3 == min_d_2: index_3 = dests.index(min_d_3, index_2 + 1) else: index_3 = dests.index(min_d_3) min_s_1 = sources[index_1] min_s_2 = sources[index_2] min_s_3 = sources[index_3] print("min_s",min_s_1,min_s_2,min_s_3) animal_1 = types[index_1] animal_2 = types[index_2] animal_3 = types[index_3] print("animal",animal_1,animal_2,animal_3) animal_type1 = types[index_1] animal_type2 = types[index_2] animal_type3 = types[index_3] loaded_1[min_s_1 - 1 : min_d_1 - 1] = [animal_type1 for x in range(min_s_1 - 1,min_d_1 - 1)] loaded_2[min_s_2 - 1 : min_d_2 - 1] = [animal_type2 for x in range(min_s_2 - 1,min_d_2 - 1)] loaded_3[min_s_3 - 1 : min_d_3 - 1] = [animal_type3 for x in range(min_s_3 - 1,min_d_3 - 1)] print("loaded_1",loaded_1) print("loaded_2",loaded_2) print("loaded_3",loaded_3) return answers # Return a list of length n consisting of the answers if __name__ == "__main__": cases = int(input().strip()) for _ in range(cases): num_zoo, num_animals = [int(x) for x in input().strip().split(' ')] types = input().strip().split(' ') sources = list(map(int, input().strip().split(' '))) dests = list(map(int, input().strip().split(' '))) result = minimumZooNumbers(num_zoo, num_animals, types, sources, dests) print (" ".join(map(str, result)))