#include using namespace std; template class segment_tree { vector _tree; vector _update; T add(unsigned node, unsigned n_from, unsigned n_to, unsigned from, unsigned to, T val) { if (to <= n_from || from >= n_to) return numeric_limits::min(); if (n_from == from && n_to == to) { _update[node] += val; return _tree[node] + _update[node]; } if (_update[node]) { _update[2*node+1] += _update[node]; _update[2*node+2] += _update[node]; _tree[node] += _update[node]; _update[node] = 0; } auto mid = n_from + (n_to - n_from)/2; auto ret = max(add(2*node+1, n_from, mid, from, min(mid, to), val), add(2*node+2, mid, n_to, max(from, mid), to, val)); _tree[node] = max(_tree[node], ret); return ret; } public: segment_tree(size_t s) { while (s & (s-1)) s += s & -s; _tree.resize(2*s-1); _update.resize(2*s-1); } T add(unsigned from, unsigned to, T val) { return add(0, 0, (_tree.size()+1)/2, from, to, val); } }; vector minimumZooNumbers(unsigned zoo_num, const vector& t, const vector& s, const vector& d) { auto type = [](char t) -> unsigned { return t == 'E' || t == 'C'; }; auto other = [](unsigned t) { return (t+1)%2; }; vector, 2>> conn(zoo_num); for (unsigned i = 0; i < t.size(); ++i) if (s[i] < d[i]) conn[d[i]-1][type(t[i])].push_back(s[i]-1); for (auto& arr: conn) for (auto& v: arr) sort(v.begin(), v.end()); array, 2> val; val[0].resize(zoo_num); val[1].resize(zoo_num); vector> tr(2, {zoo_num}); for (unsigned i = 1; i < zoo_num; ++i) { val[0][i] = val[0][i-1]; val[1][i] = val[1][i-1]; for (unsigned t = 0; t < 2; ++t) { auto& s = tr[other(t)]; const auto& c = conn[i][t]; for (unsigned j = 0; j < c.size(); ++j) val[t][i] = max(val[t][i], s.add(0, c[j]+1, 1)); tr[t].add(i, i+1, val[t][i]); } } vector ret; ret.reserve(t.size()); unsigned num = 1; for (unsigned i = 0; i < zoo_num; ++i) while (ret.size()+1 <= max(val[0][i], val[1][i])) ret.push_back(i+1); ret.resize(t.size(), -1); return ret; } int main() { ios::sync_with_stdio(false); int cases; cin >> cases; for(int a0 = 0; a0 < cases; a0++){ int zoo_num; int animal_num; cin >> zoo_num >> animal_num; vector t(animal_num); for(int t_i = 0; t_i < animal_num; t_i++) cin >> t[t_i]; vector s(animal_num); for(int s_i = 0; s_i < animal_num; s_i++) cin >> s[s_i]; vector d(animal_num); for(int d_i = 0; d_i < animal_num; d_i++) cin >> d[d_i]; vector result = minimumZooNumbers(zoo_num, t, s, d); for (ssize_t i = 0; i < result.size(); i++) { cout << result[i] << (i != result.size() - 1 ? " " : ""); } cout << endl; } return 0; }