import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int[] minimumZooNumbers(int m, int n, char[] t, int[] s, int[] d) { int[] counter = new int[m + 1]; for (int i = 0; i < n; i++) if (s[i] < d[i]) counter[d[i]]++; int[][] ind = new int[m + 1][]; for (int i = 1; i <= m; i++) { ind[i] = new int[counter[i]]; counter[i] = 0; } for (int i = 0; i < n; i++) if (s[i] < d[i]) { ind[d[i]][counter[d[i]]] = i; counter[d[i]]++; } Node whiteRoot = buildTree(1, m); Node blackRoot = buildTree(1, m); int[] maxAnimals = new int[m + 1]; for (int i = 1; i <= m; i++) { for (int j = 0; j < counter[i]; j++) { int k = ind[i][j]; if (t[k] == 'E' || t[k] == 'C') { andOne(blackRoot, s[k]); } else { andOne(whiteRoot, s[k]); } } int max = Math.max(blackRoot.value + blackRoot.plus, whiteRoot.value + whiteRoot.plus); insert(blackRoot, i, max); insert(whiteRoot, i, max); maxAnimals[i] = max; } int[] res = new int[n]; int next = 0; for (int i = 1; i <= m; i++) { while (next < maxAnimals[i]) { res[next] = i; next++; } } while (next < n) { res[next++] = -1; } return res; } static class Node { Node left; Node right; int leftBound; int rightBound; int value = 0; int plus = 0; } static Node buildTree(int left, int right) { Node node = new Node(); node.leftBound = left; node.rightBound = right; if (left == right) { return node; } int mid = (left + right) / 2; node.left = buildTree(left, mid); node.right = buildTree(mid + 1, right); return node; } static void andOne(Node node, int r) { if (r >= node.rightBound) { node.plus++; return; } if (node.plus > 0) { node.left.plus += node.plus; node.right.plus += node.plus; } andOne(node.left, r); if (r >= node.right.leftBound) { andOne(node.right, r); } updateNode(node); } static void updateNode(Node node) { node.value = Math.max(node.left.value + node.left.plus, node.right.value + node.right.plus); node.plus = 0; } static void insert(Node node, int ind, int v) { if (node.leftBound == ind && node.rightBound == ind) { node.value = v; node.plus = 0; return; } if (node.plus > 0) { node.left.plus += node.plus; node.right.plus += node.plus; } if (node.left.rightBound >= ind) { insert(node.left, ind, v); } else { insert(node.right, ind, v); } updateNode(node); } 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(); } }