#include using namespace std; int const N = 1e5 + 5; struct Route{ int type, id, l, r; Route(){}; Route(int _type, int _id, int _l, int _r){ type = _type; id = _id; l = _l; r = _r; } }; Route a[N]; int DP[N], ans[N]; struct BIT{ int tree[N]; void clear(){ memset(tree, 0, sizeof(tree)); } void update(int x){ x += 3; while(x < N){ tree[x]++; x += x & (-x); } } int get(int x){ x += 3; int r = 0; while(x){ r += tree[x]; x -= x & (-x); } return r; } }; BIT Tree[2]; vector < Route > b[2]; bool operator < (const Route &P, const Route &Q){ return P.r < Q.r; } int n, m; int getVal(char p){ if(p == 'E' || p == 'C') return 0; return 1; } int main() { // freopen("inp.txt", "r", stdin); //freopen("out.txt", "w", stdout); int T; char type; cin >> T; while(T--){ Tree[0].clear(); Tree[1].clear(); cin >> m >> n; for(int i=1; i<=n; i++){ cin >> type; a[i].type = getVal(type); a[i].id = i; } for(int i=1; i<=n; i++){ cin >> a[i].l; } for(int i=1; i<=n; i++){ cin >> a[i].r; } sort(a+1, a+n+1); b[0].clear(); b[1].clear(); b[0].push_back(Route(0, 0, 0, -1)); b[1].push_back(Route(0, 0, 0, -1)); for(int i=1; i<=n; i++){ a[i].id = i; b[a[i].type].push_back(a[i]); } for(int i=0; i<=n+1; i++) ans[i] = m + 1; for(int i=1; i<=n; i++){ int type = a[i].type; int x = lower_bound(b[type^1].begin(), b[type^1].end(), Route(0, 0, 0, a[i].l+1)) - b[type^1].begin() - 1; int id = b[type^1][x].id; Tree[type].update(a[i].l); DP[i] = DP[id] + Tree[type].get(a[i].r) - Tree[type].get(a[id].r-1); ans[DP[i]] = min(ans[DP[i]], a[i].r); } for(int i=n; i>=1; i--){ ans[i] = min(ans[i], ans[i+1]); } for(int i=1; i<=n; i++) if(ans[i] != m+1) cout << ans[i] << " "; else cout << -1 << " "; cout << endl; } }