/* not_stable but Believer */
/* Practice for Expert */
#include<bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,char>
#define pb push_back
#define f(i, n) for(int i=0;i<n;i++)
#define F(i, n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define tr cout<<"\n"
#define br break
#define mod 998244353
#define inf 1000000000009
using namespace std;
const int maxn=100005;


int solve(std::vector<int> &a, std::vector<int> &b){
int n=a.size(),m=b.size();
if(a.size()==0 || b.size()==0)return 0;
 sort(all(a));
 sort(all(b));
set<int> pos(b.begin(),b.end());//push all the b values;
vector<int> suf(n+1);
suf[n]=0;
for(int i=n-1;i>=0;i--){
	suf[i]=suf[i+1];
	if(pos.count(a[i]))suf[i]++;// al the values;
}
 int ans=suf[0];
 for(int i=0;i<a.size();i++){
 	auto id=lower_bound(all(b),a[i]);
 	if(id==b.end())break;
 	int start=id-b.begin();
 	int next=1e9+5;
 	if(i+1<n)next=a[i+1]-1;

 	while(start<m && b[start]<=next){
 		int much=lower_bound(all(b),b[start]-i)-b.begin();
 		ans=max(ans,suf[i+1]+(start-much+1));
 		++start;
 	}

}

 return ans;

}

void Not_Stable()
{
	int n,m;
	cin>>n>>m;
	std::vector<int> a,a1,b,b1;
	F(i,n){
		int val;
		cin>>val;
	    if(val<0)a.pb(val*-1);
	    else a1.pb(val);
	}
	F(i,m){
		int val;
		cin>>val;
	    if(val<0)b.pb(val*-1);
	    else b1.pb(val);
	}


	int ans=solve(a1,b1);
	ans+=(solve(a,b));
	cout<<ans;
	tr;

}


 
 
 
 
 
 
int32_t main() {
    io;

    int g;cin>>g;
    while (g--)Not_Stable();
    return 0;
}