1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 int main(int argc,const char *argv[])
6 {
7 int n;
8 scanf("%d",&n);
9 while(n--)
10 {
11
12 int sum;
13 int a,b;
14 int count = 0;
15 int A[10001];
16 memset(A,0,sizeof(A));
17 scanf("%d",&sum);
18 scanf("%d",&a);
19 for(int i = 0; i < a; ++i)
20 {
21 int tem;
22 scanf("%d",&tem);
23 if(tem >= sum)continue;
24 else
25 {
26 A[tem]++;
27 }
28 }
29 scanf("%d",&b);
30 for(int i = 0; i < b; ++i)
31 {
32 int tem;
33 scanf("%d",&tem);
34 if(tem >= sum)continue;
35 else
36 {
37 if(sum - tem > 0)
38 {
39 count = count + A[sum - tem];
40 }
41 }
42 }
43 printf("%d\n",count);
44 }
45 return 0;
46 }