#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<vector>#include<unordered_map>#include<unordered_set>#include<set>#include<map>#include<stack>#include<queue>#include<deque>#include<ctime>#defineendl'\n'#defineIOSios::sync_with_stdio(false); cin.tie(0); cout.tie(0)#definelowbit(x)(x&-x)usingnamespace std;constdouble pi =acos(-1);typedeflonglong ll;typedef pair<int,int> PII;typedef pair<long,long> PLL;constint N =5e3+10;ll a[N], b[N], r[N];boolcmp1(int x,int y){return a[x]> a[y];}boolcmp2(ll x, ll y){return x > y;}intmain(){IOS;int _; cin >> _;while(_ --){int n;cin >> n;for(int i =1; i <= n; i ++) cin >> a[i];for(int i =1; i <= n; i ++) cin >> b[i];for(int i =1; i <= n; i ++) r[i]= i;sort(r +1, r + n +1, cmp1);// r中元素是將a數(shù)組元素從高到低排序后在a中的序號,即r[1]是a數(shù)組中元素最大值的下標sort(b +1, b + n +1, cmp2);// b中元素從大到小for(int i =1; i <= n; i ++){int hi =0, lo =0;// 最高排名ll sc = a[i]+ b[1], k =2;// 本身給予最高分for(int j = n; j >=1; j --)// a中得分從低到高枚舉{ll jj = r[j];// j == n時,jj是a數(shù)組中最小元素的下標if(jj == i)continue;while(a[jj]+ b[k]> sc && k <= n)++ k ;// 找使得總得分小于等于sc的b中分數(shù)if(k <= n)++ hi ;// 找得到就 ++ ,使hi盡可能多,即在最高排名下,使得總得分小于等于sc的盡可能多++ k ;if(k > n)break;}hi = n - hi;// 剩下的分都比它高// 最低排名sc = a[i]+ b[n], k = n -1;for(int j =1; j <= n; j ++){ll jj = r[j];if(jj == i)continue;if(a[jj]> sc){++ lo ;continue;}while(a[jj]+ b[k]<= sc && k >=1)-- k ;// 找使得總得分大于sc的if(k <1)break;++ lo ;-- k ;}cout << hi <<" "<< lo +1<< endl;}}return0;}