#include <bits/stdc++.h>
#define N 200005
using namespace std;
using ll = long long;

int n, m;
vector<int> ap, an, bp, bn, cp, cn;

void solve() {
	cin>>n>>m;
	
	for (int i=0; i<n; i++) {
		int a; cin>>a;
		if (a < 0) an.push_back(-a);
		else ap.push_back(a);
	}
	for (int i=0; i<m; i++) {
		int b; cin>>b;
		if (b < 0) bn.push_back(-b);
		else bp.push_back(b);
	}

	reverse(an.begin(), an.end());
	reverse(bn.begin(), bn.end());

	n = ap.size(), m = bp.size();

	for (int i=0; i<n; i++) {
		if (binary_search(bp.begin(), bp.end(), ap[i])) {
			cp.push_back(ap[i]);
		}
	}

	int pans = cp.size();

	for (int i=0; i<m; i++) {
		int x = lower_bound(ap.begin(), ap.end(), bp[i]) - ap.begin();
		int y = upper_bound(bp.begin(), bp.end(), bp[i] - x) - bp.begin();
		
		auto z = upper_bound(cp.begin(), cp.end(), bp[i]);
		pans = max(pans, (i-y+1) + (int) (cp.end() - z));
	}

	n = an.size(), m = bn.size();

	for (int i=0; i<n; i++) {
		if (binary_search(bn.begin(), bn.end(), an[i])) {
			cn.push_back(an[i]);
		}
	}

	int nans = cn.size();

	for (int i=0; i<m; i++) {
		int x = lower_bound(an.begin(), an.end(), bn[i]) - an.begin();
		int y = upper_bound(bn.begin(), bn.end(), bn[i] - x) - bn.begin();
		
		auto z = upper_bound(cn.begin(), cn.end(), bn[i]);
		nans = max(nans, (i-y+1) + (int) (cn.end() - z));
	}


	ap.clear(), bp.clear(), cp.clear();
	an.clear(), bn.clear(), cn.clear();

	cout<<pans+nans<<endl;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int t; cin>>t;
	while (t--) solve();
}
