import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static class Node{ int s; int e; char c; public Node(int i, int j,char ch){ s = i; e = j; c = ch; } public String toString(){ String ret = "( "+Integer.toString(s)+" "+Integer.toString(e)+" "+c +")"; return ret; } } static int[] minimumZooNumbers(int m, int n, char[] t, int[] s, int[] d) { // Return a list of length n consisting of the answers ArrayList arr = new ArrayList(); for(int i = 0;i < n; i++){ arr.add(new Node(s[i], d[i],t[i])); } Collections.sort(arr, new Comparator(){ public int compare(Node i1, Node i2){ int s1 = i1.e; int s2 = i2.e; if(s1 == s2){ return i1.s - i2.s; } return s1-s2; } }); int count1 = 0; int count2 = 0; int s1 = 0; int s2 = 0; Map> arr1 = new HashMap>(); Map> arr2 = new HashMap>(); Map t1 = new HashMap(); Map t2 = new HashMap(); int [] trips = new int [m+1]; int j = 0; // System.out.println(arr); for(int i = 1; i <= m; i++){ // System.out.println(i); // System.out.println(arr1); // System.out.println(arr2); // System.out.println(t1); //System.out.println(t2); if(arr1.get(i) != null){ ArrayList temp = arr1.get(i); s1 = s1 - temp.size(); for(int k = 0; k < temp.size(); k++){ if(t1.get(temp.get(k).c) != null){ int num = t1.get(temp.get(k).c); t1.put(temp.get(k).c, num-1); if(t1.get(temp.get(k).c) == 0){ t1.remove(temp.get(k).c); } } } trips[i] = Math.max(trips[i], count1-s1); arr1.remove(i); } if(arr2.get(i) != null){ ArrayList temp = arr2.get(i); s2 = s2 - temp.size(); for(int k = 0; k < temp.size(); k++){ if(t2.get(temp.get(k).c) != null){ int num = t2.get(temp.get(k).c); t2.put(temp.get(k).c, num-1); if(t2.get(temp.get(k).c) == 0){ t2.remove(temp.get(k).c); } } } trips[i] = Math.max(trips[i], count2-s2); arr2.remove(i); } while(j < n && arr.get(j).s == i){ Node te = arr.get(j); boolean ec = te.c == 'E' || te.c == 'C'; boolean md = te.c == 'M' || te.c == 'D'; boolean t1dm = t1.get('D')!=null || t1.get('M')!=null; boolean t2dm = t2.get('D')!=null || t2.get('M')!=null; boolean t1ec = t1.get('E')!=null || t1.get('C')!=null; boolean t2ec = t2.get('E')!=null || t2.get('C')!=null; if((ec && !(t1dm)) || (md && !(t1ec)) ) { if(arr1.get(te.e) == null){ arr1.put(te.e, new ArrayList()); } //System.out.println((te.c == 'E'|| te.c == 'C') &&(!(t1.get('D')!=null||t1.get('M')!=null))); if(te.e > i){ arr1.get(te.e).add(te); s1++; if(t1.get(te.c) == null){ t1.put(te.c, 0); } t1.put(te.c, t1.get(te.c)+1); count1++; } }else if((ec && !(t2dm)) || (md && !(t2ec))){ if(arr2.get(te.e) == null){ arr2.put(te.e, new ArrayList()); } if(te.e > i){ arr2.get(te.e).add(te); s2++; if(t2.get(te.c) == null){ t2.put(te.c, 0); } t2.put(te.c, t2.get(te.c)+1); count2++; } } j++; } } int k = 1; int zo = 1; int [] min = new int [n]; Arrays.fill(min, -1); while(k <= n && zo <= m){ if(trips[zo] >= k){ min[k-1] = zo; k++; }else{ zo++; } } return min; } 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(); } }