import java.lang.Math; import java.io.*; import java.util.*; public class Main { public static class Trip implements Comparable { public char type; public int s; public int d; public Trip(char type, int s, int d) { this.type = type; this.s = s; this.d = d; } @Override public int compareTo(Trip o) { if(d < o.d) return -1; else if(o.d < d) return 1; else if(s < o.s) return -1; else if(o.s < s) return 1; return 0; } } static BufferedReader in; static PrintStream out; static StringTokenizer tok; static int[] minimumZooNumbers(int m, int n, char[] t, int[] s, int[] d) { int[] ans = new int[1]; return ans; } @SuppressWarnings("empty-statement") public static void main(String[] args) throws NumberFormatException, IOException { //in = new BufferedReader(new InputStreamReader(System.in)); //in = new BufferedReader(new FileReader("metro.txt")); //out = System.out; 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(); } ArrayList ac = new ArrayList(); ArrayList dm = new ArrayList(); int[] d = new int[n]; for(int d_i = 0; d_i < n; d_i++){ d[d_i] = in.nextInt(); Trip trip = new Trip(t[d_i], s[d_i], d[d_i]); if(trip.type == 'E' || trip.type == 'C') { ac.add(trip); } else { dm.add(trip); } } Collections.sort(ac); Collections.sort(dm); int[] dpAC = new int[m + 1]; int[] dpDM = new int[m + 1]; int i_ac = 0; int j_dm = 0; for(int pos = 1; pos <= m; pos++) { int nextACending = Integer.MAX_VALUE; int nextDMending = Integer.MAX_VALUE; if(i_ac < ac.size()) nextACending = ac.get(i_ac).d; if(j_dm < dm.size()) nextDMending = dm.get(j_dm).d; int min = Math.min(nextACending, nextDMending); if(min > pos)//done with all trips { dpAC[pos] = dpAC[pos - 1]; dpDM[pos] = dpDM[pos - 1]; continue; } if(nextACending == pos) { int firstEndingHere = i_ac; do { Trip ac_nextTrip = ac.get(i_ac); int add = (i_ac-firstEndingHere + 1);//adding this number of a-c animals int sameType = add + dpAC[pos-1];// int difType = add + dpDM[ac_nextTrip.s]; int tempMax = Math.max(sameType, difType); dpAC[pos] = Math.max(dpAC[pos], tempMax);//update dp i_ac++; } while(i_ac < ac.size() && ac.get(i_ac).d == ac.get(firstEndingHere).d); } if(nextDMending == pos) { int firstEndingHere = j_dm; do { Trip dm_nextTrip = dm.get(j_dm); int add = (j_dm-firstEndingHere + 1);//adding this number of a-c animals int sameType = add + dpDM[pos-1];// int difType = add + dpAC[dm_nextTrip.s]; int tempMax = Math.max(sameType, difType); dpDM[pos] = Math.max(dpDM[pos], tempMax);//update dp j_dm++; } while(j_dm < dm.size() && dm.get(j_dm).d == dm.get(firstEndingHere).d); } } int[] result = new int[n+1]; Arrays.fill(result, -1); result[0] = 0; int[] dp = new int[m + 1]; for (int i = 0; i <= m; i++) { dp[i] = Math.max(dpAC[i], dpDM[i]); int number = dp[i]; while(result[number] == -1) { result[number] = i; number--; } } for (int i = 1; i < result.length; i++) { System.out.print(result[i] + (i != result.length - 1 ? " " : "")); } System.out.println(""); } } static String nextToken() throws IOException { String line = ""; while(tok == null || !tok.hasMoreTokens()) { if((line = in.readLine()) != null) tok = new StringTokenizer(line); else return null; } return tok.nextToken(); } static int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws NumberFormatException, IOException { return Long.parseLong(nextToken()); } }