# include<bits/stdc++.h>

using namespace std;
# define l long long 
# define db double 
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 

#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const bool MULTIPLE_TEST_CASES = true;

const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;

l solveForOne(vi &a, vi &b) {
	if(b.size()==0) {
		return 0;
	}
	l n=a.size();
	l m=b.size();
	vi maxCont(m,0);
	maxCont[0]=1;
	rep(i,1,m) {
		if(b[i-1]+1==b[i]) {
			maxCont[i] = maxCont[i-1]+1;
		} else {
			maxCont[i] = 1;
		}
	}
	dbg(maxCont);
	// 
	l a_idx = n-1;
	l b_idx = m-1;
	l match = 0;
	l best = 0;
	if(b_idx>=0) {
		while(a_idx>=0 && a[a_idx]>b[b_idx]) {
			a_idx--;
		}
	}
	while(a_idx>=0 && b_idx>=0) {
		l cont = maxCont[b_idx];
		l numSpecial = b.begin() + b_idx - lower_bound(b.begin(), b.begin()+b_idx, b[b_idx]-a_idx) + 1;
		l curBest = min(numSpecial, a_idx+1) + match;
		dbg(curBest);
		best = max(best, curBest);
		if(a[a_idx]==b[b_idx]) {
			match++;
		}
		b_idx--;
		if(b_idx>=0) {
			while(a_idx>=0 && a[a_idx]>b[b_idx]) {
				a_idx--;
			}
		}
	}
	// return 0;
	return best;
}

void solve() {
	l n,m;
	cin>>n>>m;
	vi a(n), b(m);
	vi a_pos, a_neg, b_pos, b_neg;
	rep(i,0,n) {
		cin>>a[i];
		if(a[i]>0) {
			a_pos.push_back(a[i]);
		} else {
			a_neg.push_back(-a[i]);
		}
	}

	rep(i,0,m) {
		cin>>b[i];
		if(b[i]>0) {
			b_pos.push_back(b[i]);
		} else {
			b_neg.push_back(-b[i]);
		}
	}
	dbg(a);
	dbg(b);
	dbg(a_pos);
	dbg(b_pos);
	
	// return;
	reverse(a_neg.begin(), a_neg.end());
	reverse(b_neg.begin(), b_neg.end());
	dbg(a_neg);
	dbg(b_neg);
	l ans = solveForOne(a_pos, b_pos);
	ans += solveForOne(a_neg, b_neg);
	cout<<ans<<"\n";
	
	


	return;
}


int main(){
	io;
	int t=1;
	if (MULTIPLE_TEST_CASES) cin>>t;
	rep(i,0,t) {
		solve();
	}

	return 0;
}
