# include <iostream>
# include <fstream>
# include <sstream>
# include <algorithm>
# include <cstdio>
# include <cmath>
# include <numeric>
# include <cstdlib>
# include <cstring>
# include <vector>
# include <list>
# include <set>
# include <map>
# include <stack>
# include <queue>
# include <cctype>
# include <climits>
# include <complex>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inf 1000000000
#define mod 1000000007
#define mst(a,b) memset(a,b,sizeof(a))
#define pi (double)(3.141592653589793)
long long p[100010],q[100010],r[100010],xx[100010],yy[100010];
int main()
{
long long t,i,j,k,a,b,c,x;
cin>>t;
long long sum=0;
while(t--)
{
sum=0;
scanf("%lld",&a);
for(i=1;i<=a;i++)
scanf("%lld",&p[i]);
scanf("%lld",&b);
for(i=1;i<=b;i++)
scanf("%lld",&q[i]);
scanf("%lld",&c);
for(i=1;i<=c;i++)
scanf("%lld",&r[i]);
for(i=1;i<=b;i++)
{
x=(lower_bound(r+i,r+c+1,q[i])-(r));
xx[i]=c-x+1;
}
for(i=(b-1);i>=1;i--)
{
xx[i]+=xx[i+1];
}
for(i=1;i<=a;i++)
{
x=(lower_bound(q+i,q+b+1,p[i])-(q));
yy[i]=x;
}
for(i=1;i<=a;i++)
if(yy[i]<=b)
sum+=(xx[yy[i]]);
cout<<sum<<endl;
}
return 0;
}
IyBpbmNsdWRlIDxpb3N0cmVhbT4KIyBpbmNsdWRlIDxmc3RyZWFtPgojIGluY2x1ZGUgPHNzdHJlYW0+CiMgaW5jbHVkZSA8YWxnb3JpdGhtPgojIGluY2x1ZGUgPGNzdGRpbz4KIyBpbmNsdWRlIDxjbWF0aD4KIyBpbmNsdWRlIDxudW1lcmljPgojIGluY2x1ZGUgPGNzdGRsaWI+CiMgaW5jbHVkZSA8Y3N0cmluZz4KIyBpbmNsdWRlIDx2ZWN0b3I+CiMgaW5jbHVkZSA8bGlzdD4KIyBpbmNsdWRlIDxzZ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iAgICAgICBmb3IoaT0xO2k8PWM7aSsrKQogICAgICAgIHNjYW5mKCIlbGxkIiwmcltpXSk7CiAgICAKICAgICAgICBmb3IoaT0xO2k8PWI7aSsrKQogICAgICAgIHsKICAgICAgICAgICAgeD0obG93ZXJfYm91bmQocitpLHIrYysxLHFbaV0pLShyKSk7CiAgICAgICAgICAgIHh4W2ldPWMteCsxOwogICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIGZvcihpPShiLTEpO2k+PTE7aS0tKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB4eFtpXSs9eHhbaSsxXTsKICAgICAgICAgICAgICAKICAgICAgICAgICAgfQogICAgICAgIGZvcihpPTE7aTw9YTtpKyspCiAgICAgICAgewogICAgICAgICAgICB4PShsb3dlcl9ib3VuZChxK2kscStiKzEscFtpXSktKHEpKTsKICAgICAgICAgICAgeXlbaV09eDsKICAgICAgICAgCiAgICAgICAgfQogICAgICAgIGZvcihpPTE7aTw9YTtpKyspCiAgICAgICAgaWYoeXlbaV08PWIpCiAgICAgICAgICAgIHN1bSs9KHh4W3l5W2ldXSk7CiAgICAgICAgY291dDw8c3VtPDxlbmRsOwoKICAgIH0KICAgIHJldHVybiAwOwp9