#include using namespace std; #define pb push_back #define mp make_pair #define F first #define S second #define fo(i, n) for(int i = 1; i <= n; ++i) typedef long long ll; typedef pair pii; typedef pair pll; const int N = 200200; const int mod = 1e9 + 7; int m, n; int s[N], d[N]; int e[N]; vector g[N]; int best[N]; inline int get(char x) { if(x == 'C')return 3; if(x== 'E') return 1; if(x == 'D') return 2; return 4; } int dp[N]; vector > prs; bool ok[5]; int t[5][N]; int add[5][N * 2]; int tickay[5]; inline void push(int id, int v) { if(add[id][v]) { add[id][v + v] += add[id][v]; add[id][v + v + 1] += add[id][v]; t[id][v + v] += add[id][v]; t[id][v + v + 1] += add[id][v]; add[id][v] = 0; } } inline void upd(int id, int v, int tl, int tr,int l, int r, int x) { if(l > r) return; if(tl == l && tr == r) { add[id][v] += x; t[id][v] += x; return; } push(id, v); int tm = tl + tr >> 1; upd(id, v + v, tl, tm, l, min(r, tm), x); upd(id, v + v + 1, tm + 1, tr, max(tm + 1, l), r, x); t[id][v] = max(t[id][v + v], t[id][v + v + 1]); } inline void solve() { scanf("%d%d\n", &m, &n); fo(i, m) g[i].clear(); fo(i, n) { char ch; scanf("%c ", &ch); e[i] = get(ch); } fo(i, n) scanf("%d", s + i); fo(i, n) { scanf("%d", d + i); if(s[i] < d[i]) { g[d[i]].pb(mp(s[i], e[i])); } } fo(i, m) { sort(g[i].begin(), g[i].end()); reverse(g[i].begin(), g[i].end()); } for(int i = 1; i <= 2; ++i) for(int j = 1 ; j <= 4 * m; ++j) t[i][j] = add[i][j] = 0;; fo(i, m) dp[i] = 0; for(int i = 1; i <= m; ++i) { int R = i; dp[i] = max(dp[i], dp[i - 1]); for(int j = 0; j < g[i].size(); ++j) upd(tickay[g[i][j].S], 1, 1, m, 1, g[i][j].F, 1); dp[i] = max(dp[i], max(t[1][1], t[2][1])); upd(1, 1, 1, m, i, i, dp[i]); upd(2, 1, 1, m, i, i, dp[i]); } fo(i, n) best[i] = 1e9; fo(i, m) best[dp[i]] = min(best[dp[i]], i); for(int i = n - 1; i >= 1; --i) best[i] = min(best[i], best[i + 1]); for(int i = 1; i <= n; ++i) if(best[i] != 1e9) printf("%d ", best[i]); else printf("-1 "); puts(""); } int main() { tickay[1] = 1; tickay[3] = 1; tickay[2] = 2; tickay[4] = 2; prs.pb({1, 3}); prs.pb({2, 4}); int t; scanf("%d", &t); while(t-- ) solve(); return 0; }