/** * Created by Aminul on 12/16/2017. */ import java.io.*; import java.util.*; public class Animal_Transport { static int n, m, dp[][], a[], source[], dest[], ans[]; static List list_d[], list_c[]; public static void main(String[] args) throws Exception { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); /* dogs and mice are same, type = 0 cats and elephants are same, type = 1; */ int test = in.nextInt(); for(int t = 1; t <= test; t++){ m = in.nextInt(); n = in.nextInt(); if(a == null || a.length < n){ a = new int[n+1]; source = new int[n+1]; dest = new int[n+1]; } list_d = new List[m+1]; list_c = new List[m+1]; for(int i = 0; i <= m; i++){ list_d[i] = new ArrayList<>(); list_c[i] = new ArrayList<>(); } for(int i = 1; i <= n; i++){ char x = in.nextChar(); if(x == 'M' || x == 'D') a[i] = 0; if(x == 'E' || x == 'C') a[i] = 1; } for(int i = 1; i <= n; i++){ source[i] = in.nextInt(); } for(int i = 1; i <= n; i++){ dest[i] = in.nextInt(); if(source[i] <= dest[i]) { //debug(dest[i], list_d.length); if (a[i] == 0) list_d[dest[i]].add(new Node(source[i], dest[i], a[i])); else list_c[dest[i]].add(new Node(source[i], dest[i], a[i])); } } for(List l : list_d){ Collections.sort(l); } for(List l : list_c){ Collections.sort(l); } dp = new int[2][m+1]; solve(); generateAnswer(); for(int i = 1; i <= n; i++){ pw.print(ans[i]+" "); } pw.println(); } pw.close(); } static void generateAnswer(){ ans = new int[n+1]; Arrays.fill(ans, -1); for(int i = 1; i <= m; i++){ int x = dp[0][i]; if(ans[x] == -1) ans[x] = i; else ans[x] = Math.min(ans[x], i); x = dp[1][i]; if(ans[x] == -1) ans[x] = i; else ans[x] = Math.min(ans[x], i); } } static void solve(){ for(int i = 1; i <= m; i++){ dp[0][i] = dp[0][i-1]; dp[1][i] = dp[1][i-1]; int j = 1; for(Node node : list_c[i]){ dp[1][i] = Math.max(dp[1][i], Math.max(dp[1][i] + 1 , j + dp[0][node.s])); j++; } j = 1; for(Node node : list_d[i]){ dp[0][i] = Math.max(dp[0][i], Math.max(dp[0][i] + 1 , j + dp[1][node.s])); j++; } } } static class Node implements Comparable{ int s, d, t; Node(int S, int D, int T){ s = S; d = D; t = T; } public int compareTo(Node node){ return - s + node.s; } } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; static final int ints[] = new int[128]; public FastReader(InputStream is) { for (int i = '0'; i <= '9'; i++) ints[i] = i - '0'; this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + ints[b]; } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + ints[b]; } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char nextChar() { return (char)skip(); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } /*private char buff[] = new char[1005]; public char[] nextCharArray(){ int b = skip(), p = 0; while(!(isSpaceChar(b))){ buff[p++] = (char)b; b = readByte(); } return Arrays.copyOf(buff, p); }*/ } }