import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static class Animal implements Comparable { char type; int source; int destination; public Animal (char t, int s, int d) { type = t; source = s; destination = d; } public char getType() { return type; } public int getDestinationZoo() { return destination; } public int getSourceZoo() { return source; } @Override public int compareTo(Animal other) { return this.destination - other.getDestinationZoo(); } public boolean canTravelWith(Animal other) { switch(type) { case 'E': if (other.getType() == 'C') return true; else { if (other.getDestinationZoo() <= this.source) return true; else return false; } case 'D': if (other.getType() == 'M') return true; else { if (other.getDestinationZoo() <= this.source) return true; else return false; } case 'C': if (other.getType() == 'E') return true; else { if (other.getDestinationZoo() <= this.source) return true; else return false; } case 'M': if (other.getType() == 'D') return true; else { if (other.getDestinationZoo() <= this.source) return true; else return false; } } return false; } } static int[] minimumZooNumbers(int m, int n, char[] t, int[] s, int[] d) { ArrayList animals = new ArrayList(); for (int i = 0; i < n; i++) { Animal newAnimal = new Animal(t[i], s[i], d[i]); animals.add(newAnimal); } Collections.sort(animals); ArrayList tmpResult = new ArrayList(); int currentMax = Integer.MIN_VALUE; for (int i = 0; i < animals.size(); i++) { int animalCnt = 1; // the current animal Animal current = animals.get(i); for (int j = 0; j < i ; j++) { if (current.canTravelWith(animals.get(j))) animalCnt++; } if (animalCnt > currentMax) { currentMax = animalCnt; tmpResult.add(current.getDestinationZoo()); } } for (int i = tmpResult.size(); i < n; i++) { tmpResult.add(-1); } int[] result = new int[tmpResult.size()]; for (int i = 0; i < n; i++) { result[i] = tmpResult.get(i); } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int cases = in.nextInt(); for(int a0 = 0; a0 < cases; a0++){ int m = in.nextInt(); int n = in.nextInt(); char[] t = new char[n]; for(int t_i = 0; t_i < n; t_i++){ t[t_i] = in.next().charAt(0); } int[] s = new int[n]; for(int s_i = 0; s_i < n; s_i++){ s[s_i] = in.nextInt(); } int[] d = new int[n]; for(int d_i = 0; d_i < n; d_i++){ d[d_i] = in.nextInt(); } int[] result = minimumZooNumbers(m, n, t, s, d); for (int i = 0; i < result.length; i++) { System.out.print(result[i] + (i != result.length - 1 ? " " : "")); } System.out.println(""); } in.close(); } }