#include using namespace std; const int N = 1e5 +10; struct BIT { int bit[N]; void update(int i, int v) { for(; i < N; i += i & -i) bit[i] = max(bit[i], v); } int get(int i, int ans = 0) { for(; i > 0; i -= i & -i) ans = max(ans, bit[i]); return ans; } void clear() { memset(bit, 0, sizeof bit); } } node[3]; struct Animal { char type; int start, desti; } animal[N]; int m, n; int f[N]; bool cmp(Animal a, Animal b) { return a.desti < b.desti; } void Enter() { cin >> m >> n; for(int i = 1; i <= n; ++i) cin >> animal[i].type; for(int i = 1; i <= n; ++i) cin >> animal[i].start; for(int i = 1; i <= n; ++i) cin >> animal[i].desti; } void Solve() { sort(animal +1, animal +n +1, cmp); // for(int i = 1; i <= n; ++i) // cout << animal[i].type << ' ' << animal[i].start << ' ' << animal[i].desti << '\n'; for(int i = 0; i <= 2; ++i) node[i].clear(); memset(f, 0, sizeof f); for(int i = 1; i <= n; ++i) { f[i] = node[2].get(animal[i].start) +1; if (animal[i].type == 'E' || animal[i].type == 'C') { f[i] = max(f[i], node[0].get(animal[i].desti) + 1); node[0].update(animal[i].desti, f[i]); } else { f[i] = max(f[i], node[1].get(animal[i].desti) + 1); node[1].update(animal[i].desti, f[i]); } node[2].update(animal[i].desti, f[i]); } for(int i = 1; i <= n; ++i) { int lo = 1, hi = n, ans = -1; while (lo <= hi) { int mid = lo+hi >> 1; if (f[mid] >= i) ans = animal[mid].desti, hi = mid-1; else lo = mid+1; } cout << ans << ' '; } cout << '\n'; } int main() { int nTest; cin >> nTest; while (nTest --) { Enter(); Solve(); } return 0; }