#include
//#include
#include
#include
#include
#define MOD 1000000007
#define ll long long
using namespace std;
int main() {
int t;
cin >>t;
while(t--){
int n,m;
cin >> n;
set ms1;
set ms2;
multiset tempms1;
multiset tempms2;
double avrg1, avrg2;
int res = 0;
double sum1 = 0,sum2 = 0;
for(int i =0;i> a;
sum1+=a;
ms1.insert(a);
tempms1.insert(a);
}
cin >> m;
for(int i =0;i> a;
ms2.insert(a);
sum2+=a;
tempms2.insert(a);
}
avrg1 = sum1 / n;
avrg2 = sum2 / m;
for(auto x : ms1){
double tempavrg1, tempavrg2;
tempavrg1 = (sum1-x)/(n-1);
tempavrg2 = (sum2+x)/(m+1);
if(tempavrg1>avrg1 and tempavrg2>avrg2){
res+= tempms1.count(x);
}
}
for(auto x:ms2){
double tempavrg1, tempavrg2;
tempavrg1 = (sum1+x)/(n+1);
tempavrg2 = (sum2-x)/(m-1);
if(tempavrg1>avrg1 and tempavrg2>avrg2){
res+= tempms2.count(x);
}
}
cout << res<