#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N; cin >> N; vector A(N),B(N); for(auto &a : A) cin >> a; for(auto &a : B) cin >> a; vector dp1(N+1,1001001001),dp2(N+1,1001001001); auto add = [&](int x) -> void { int pos = lower_bound(dp1.begin(),dp1.end(),x)-dp1.begin(); if(dp1.at(pos) != 1001001001){ int pos2 = lower_bound(dp2.begin(),dp2.end(),dp1.at(pos))-dp2.begin(); dp2.at(pos2) = dp1.at(pos); } dp1.at(pos) = x; }; for(int i=0; i