#include using namespace std; typedef long long ll; typedef vector vl; typedef vector vvl; typedef pair pll; typedef vector vb; const ll oo = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define FOR(i,a,b) for (ll i = (a); i < (b); i++) #define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define xx first #define yy second #define has(c,i) ((c).find(i) != end(c)) #define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; }) template struct segtree { ll n, H; T zero; vector value; U noop; vector dirty; vector prop; segtree(ll n, T zero = T(), U noop = U()): n(n), zero(zero), noop(noop) { H = 0; while ((1 << H) < 2*n) H++; value.resize(2*n,zero); dirty.resize(n,false); prop.resize(n,noop); } void set_leaves(vector &leaves) { copy(all(leaves),begin(value)+n); FORD(i,1,n) value[i] = value[2*i] + value[2*i+1]; } void apply(ll i, U &upd) { value[i] = upd(value[i]); if (i < n) prop[i] = prop[i] + upd, dirty[i] = true; } void rebuild(ll i) { for (i /= 2; i; i /= 2) value[i] = prop[i](value[2*i] + value[2*i+1]); } void propagate(ll i) { FORD(h,1,H+1) if (dirty[i >> h]) { ll j = i >> h; apply(2*j,prop[j]), apply(2*j+1,prop[j]); prop[j] = noop, dirty[j] = false; } } void update(ll i, ll j, U upd) { i += n, j += n; propagate(i), propagate(j-1); for (ll l = i, r = j; l < r; l /= 2, r /= 2) { if (l & 1) apply(l++,upd); if (r & 1) apply(--r,upd); } rebuild(i), rebuild(j-1); } T query(ll i, ll j) { i += n, j += n; propagate(i), propagate(j-1); T resl = zero, resr = zero; for (; i < j; i /= 2, j /= 2) { if (i & 1) resl = resl + value[i++]; if (j & 1) resr = value[--j] + resr; } return resl + resr; } }; struct node { ll a; node operator+(node n) { return {max(a,n.a)}; } }; struct update { ll da; node operator()(node n) { return {n.a+da}; } update operator+(update u) { return {da+u.da}; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll tc; cin >> tc; while (tc--) { ll m, n; cin >> n >> m; vector> S; S.pb(segtree(n,{0},{0})); S.pb(segtree(n,{0},{0})); vector a(m); vl s(m), t(m); FOR(i,0,m) cin >> a[i]; FOR(i,0,m) cin >> s[i]; FOR(i,0,m) cin >> t[i]; vector> animals(2); FOR(i,0,m) if (s[i] < t[i]) animals[a[i] == 'E' || a[i] == 'C'].eb(t[i]-1,s[i]-1); FOR(c,0,2) sort(all(animals[c])); vvl dp(2,vl(n)); vl j(2); FOR(i,0,n) { FOR(c,0,2) { while (j[c] < sz(animals[c])) { ll s, t; tie(t,s) = animals[c][j[c]]; if (t > i) break; S[c].update(0,s+1,{1}); j[c]++; } } FOR(c,0,2) { dp[c][i] = S[c].query(0,i).a; } FOR(c,0,2) { S[!c].update(i,i+1,{dp[c][i]}); } } //FOR(c,0,2) FOR(i,0,n) cout << dp[c][i] << " \n"[i+1==n]; vl res(n); FOR(i,0,n) res[i] = max(dp[0][i],dp[1][i]); FOR(k,1,m+1) { auto it = lower_bound(all(res),k); cout << (it != end(res) ? (it-begin(res))+1 : -1) << " \n"[k==m]; } } }