#include #define lsb(x) (x & (-x)) #define ll long long using namespace std; const int MAXN = (int) 5e4; char v[MAXN + 1]; int s[MAXN + 1], d[MAXN + 1]; int dp[MAXN + 1]; vector ind[MAXN + 1]; int to[200]; pair aint[2][4 * MAXN + 1]; inline void prop(int nod, bool t) { if(2 * nod + 1 <= 4 * MAXN + 1) { aint[t][2 * nod].second += aint[t][nod].second; aint[t][2 * nod + 1].second += aint[t][nod].second; } } inline void solve_lazy(int nod, bool t) { prop(nod, t); aint[t][nod].first += aint[t][nod].second; aint[t][nod].second = 0; } void update(int nod, int left, int right, int l, int r, int val, bool t) { solve_lazy(nod, t); if(l <= left && right <= r) { aint[t][nod].second += val; solve_lazy(nod, t); } else { int med = (left + right) / 2; if(l <= med) update(2 * nod, left, med, l, r, val, t); if(med < r) update(2 * nod + 1, med + 1, right, l, r, val, t); solve_lazy(2 * nod, t); solve_lazy(2 * nod + 1, t); aint[t][nod].first = max(aint[t][2 * nod].first, aint[t][2 * nod + 1].first); } } int main(){ //ifstream cin("A.in"); //ofstream cout("A.out"); int n, i, m, t, j; ios::sync_with_stdio(false); to['E'] = 0; to['D'] = 1; to['C'] = 2; to['M'] = 3; cin >> t; while(t > 0) { t--; cin >> m >> n; for(i = 1; i <= n; i++) { cin >> v[i]; } for(i = 1; i <= m; i++) { ind[i].clear(); } for(i = 1; i <= n; i++) { cin >> s[i]; } for(i = 1; i <= n; i++) { cin >> d[i]; if(d[i] > s[i]) ind[d[i]].push_back(i); } memset(aint, 0, sizeof(aint)); for(i = 1; i <= m; i++) { dp[i] = dp[i - 1]; int cnt = 0; for(auto it : ind[i]) { update(1, 1, m, 1, s[it], 1, to[v[it]] % 2); } dp[i] = max(max(dp[i], aint[0][1].first), aint[1][1].first); for(j = 0; j < 2; j++) update(1, 1, m, i, i, dp[i], j); } for(i = 1; i <= n; i++) { int rez = 0; for(int pas = 1 << 16; pas; pas >>= 1) { if(rez + pas <= m && i > dp[rez + pas]) rez += pas; } rez++; if(rez == m + 1) cout << -1; else cout << rez; cout << " "; } cout << endl; } //cin.close(); //cout.close(); return 0; }