#!/bin/python3 import sys from colections import deque def minimumZooNumbers(total_zoos, total_animals, type_animal, sources, destinations): out_string = "" for i in range(len(total_animals)) out_string += "-1 " print(out_string) # Return a list of length n consisting of the answers list_dest = {} list_animals = {} count = 0 for source in sources: if source not in list_dest: list_dest[source] = [destinations[count]] key = source + "-" + destinations[count] list_animals[key] = type_animal[count] count += 1 source_array.add(i+1) for source in sources: list_dest[source].sort() for total in range(1, total_animals+1): current = 0 queue = deque() for i in range(total_animals): queue.add(i) if i in list_dest: for i_dest in list_dest: if current == total: out_string += dest if __name__ == "__main__": cases = int(input().strip()) for a0 in range(cases): m, n = input().strip().split(' ') m, n = [int(m), int(n)] t = input().strip().split(' ') s = list(map(int, input().strip().split(' '))) d = list(map(int, input().strip().split(' '))) result = minimumZooNumbers(m, n, t, s, d) print (" ".join(map(str, result)))