#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while (T--) { int N; cin >> N; vector A(N), B(N); for (auto &x : A) cin >> x; for (auto &x : B) cin >> x; vector a, b; auto insert = [&](int x) { auto it = lower_bound(a.begin(), a.end(), x); if (it == a.end()) { a.push_back(x); return; } int y = *it; *it = x; auto jt = lower_bound(b.begin(), b.end(), y); if (jt == b.end()) b.push_back(y); else *jt = y; }; for (int i = 0; i < N; i++) { insert(max(A[i], B[i])); insert(min(A[i], B[i])); } cout << a.size() + b.size() << '\n'; } }