import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; /** * * @author Ashu */ class FastReader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public FastReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[512]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) { return; } din.close(); } } public class AnimalProblem { private static class Line { public int x, y; public Line(int x, int y) { if (x < y) { this.x = x; this.y = y; } else { this.x = y; this.y = x; } } public boolean cross(Line x) { return !((x.x == this.y) || (this.x == x.y)) && ((x.x >= this.x && x.x <= this.y) || (this.y >= this.x && x.y <= this.y)); } } public static class Fauna { public static enum Type { D, E, C, M } Type tp; public Fauna(char c) { switch (c) { case 'D': this.tp = Type.D; break; case 'E': this.tp = Type.E; break; case 'C': this.tp = Type.C; break; default: this.tp = Type.M; } } public boolean checkT(Fauna v) { return (v.tp == Type.D && this.tp == Type.E) || (v.tp == Type.E && this.tp == Type.D) || (v.tp == Type.C && this.tp == Type.D) || (v.tp == Type.D && this.tp == Type.C) || (v.tp == Type.M && this.tp == Type.C) || (v.tp == Type.C && this.tp == Type.M) || (v.tp == Type.E && this.tp == Type.M) || (v.tp == Type.M && this.tp == Type.E); } } private static class Path { public Fauna fType; public Line route; public Path(char type, int from, int to) { this.fType = new Fauna(type); this.route = new Line(from, to); } public boolean isRoute(Path p) { boolean t = !this.fType.checkT(p.fType); boolean flag = t || (!t && !this.route.cross(p.route)); return flag; } } private static class Group { public HashSet group; public int[] end = null; public Group() { this.group = new HashSet<>(); } public boolean add(Path p) { boolean flag = true; if (group.isEmpty()) { this.group.add(p); return flag; } for (Path k : this.group) { if (!k.isRoute(p)) { flag = false; break; } } if (flag) { group.add(p); } return flag; } public int findD(int n) { int s = group.size(); if (n >= s) { return Integer.MAX_VALUE; } if (end == null) { end = new int[s]; int i = 0; for (Path k : group) { end[i++] = k.route.y; } Arrays.sort(end); } return end[n]; } } private static class Route { private final HashSet setRoute; private final int[] countM; public Route(int n) { this.setRoute = new HashSet<>(); this.countM = new int[n]; } public void addR(char chr, int st, int en) { Path p = new Path(chr, st, en); boolean flag = false; for (Group g : this.setRoute) { if (g.add(p)) { flag = true; } } if (!flag) { Group g = new Group(); g.add(p); this.setRoute.add(g); } } public int[] solve() { int len = countM.length; for (int i = 0; i < len; i++) { int min = Integer.MAX_VALUE; for (Group arg : setRoute) { min = Math.min(min, arg.findD(i)); } countM[i] = (min == Integer.MAX_VALUE) ? -1 : min; } return countM; } } public static void main(String... args) throws IOException { FastReader scan = new FastReader(); int tc = scan.nextInt(); while (tc-- != 0) { int m = scan.nextInt(); int n = scan.nextInt(); Route r = new Route(n); String[] t = scan.readLine().split(" "); int[] s = new int[n], d = new int[n]; for (int i = 0; i < n; i++) { s[i] = scan.nextInt(); } for (int i = 0; i < n; i++) { d[i] = scan.nextInt(); } for (int i = 0; i < n; i++) { r.addR(t[i].charAt(0), s[i], d[i]); } int[] res = r.solve(); for (int i : res) { System.out.print(i + " "); } System.out.print('\n'); } } }