#include <iostream>
//#include <bits/stdc++.h>
#include <fstream>
#include <string>
#include <set>

#define MOD 1000000007
#define ll long long
using namespace std;

int main() {
    int t;
    cin >>t;
    while(t--){
        int n,m;
        cin >> n;
        set<double> ms1;
        set<double> ms2;
        multiset<double> tempms1;
        multiset<double> tempms2;
        double avrg1, avrg2;
        int res = 0;
        double sum1 = 0,sum2 = 0;
        for(int i =0;i<n;i++){
            double a;
            cin >> a;
            sum1+=a;
            ms1.insert(a);
            tempms1.insert(a);
        }
        cin  >> m;
        for(int  i =0;i<m;i++){
            double a;
            cin >> 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<<endl;
        
    }
    
}
