#include using namespace std; using ll = long long; #define rep(i,a,b) for(ll i = (a); i < (b); i++) #define all(a) (a).begin(), (a).end() const ll inf = 2'000'000'000'000'000'000; int main() { int t; cin >> t; while(t--){ int n; cin >> n; vector a(n),b(n); rep(i,0,n) cin >> a[i]; rep(i,0,n) cin >> b[i]; vector c(n*2); rep(i,0,n) { c[i*2] = a[i]; c[i*2+1] = b[i]; if(c[i*2] < c[i*2+1]) swap(c[i*2], c[i*2+1]); } rep(i,0,n*2) { c[i] = c[i] * 2*n + (2*n-1-i); } vector dp1(n*2, inf), dp2(n*2, inf); rep(i,0,n*2) { int pos = upper_bound(all(dp1), c[i]) - dp1.begin(); ll nx = dp1[pos]; dp1[pos] = c[i]; if(nx == inf) continue; pos = upper_bound(all(dp2), nx) - dp2.begin(); dp2[pos] = nx; } cout << (lower_bound(all(dp1), inf)-dp1.begin()) + (lower_bound(all(dp2), inf)-dp2.begin()) << endl; } }