#!/bin/python import sys from operator import itemgetter # precondition a2[2] >= a2[1] def is_conflict(a1, a2): s2 = a2[1] d1 = a1[2] if s2 >= d1: return False t1 = a1[0] t2 = a2[0] if t1 == 'D' and (t2 == 'C' or t2 == 'E'): return True if t1 == 'C' and (t2 == 'D' or t2 == 'M'): return True if t1 == 'M' and (t2 == 'E' or t2 == 'C'): return True if t1 == 'E' and (t2 == 'D' or t2 == 'M'): return True return False def minimumZooNumbers(m, n, t, s, d): # Return a list of length n consisting of the answers big_list=[] for i in range(0, n): big_list.append([t[i],s[i],d[i]]) big_list.sort(key=itemgetter(2, 1)) #print big_list conflicts = set() for i in range(0, n): for j in range(i + 1, n): if is_conflict(big_list[i], big_list[j]): conflicts.add((i, j)) #print conflicts to_return = [] to_return.append(big_list[0][2]) for i in range(1, n): counter = [i for i in range(0, i + 1)] while counter[0] != n - len(counter) + 1: counter[len(counter) - 1] += 1 if counter[len(counter) - 1] == n: spot = 2 while True: if len(counter) - spot < 0: break counter[len(counter) - spot] += 1 if counter[len(counter) - spot] == n + 1 - spot: spot += 1 else: value = counter[len(counter) - spot] for i in range(spot - 1, 0, -1): counter[len(counter) - i] = value + 1 value += 1 break to_return.append(-1) return to_return if __name__ == "__main__": cases = int(raw_input().strip()) for a0 in xrange(cases): m, n = raw_input().strip().split(' ') m, n = [int(m), int(n)] t = raw_input().strip().split(' ') s = map(int, raw_input().strip().split(' ')) d = map(int, raw_input().strip().split(' ')) result = minimumZooNumbers(m, n, t, s, d) print " ".join(map(str, result))