#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
vector<int> v1[2], v2[2];
int a[N], b[N];
int suf[N], occupy[N];
int solve(int x)
{
	int n = v1[x].size() - 2, m = v2[x].size() - 2;
	// cout << "solve " << x << endl;
	int ans = 0;
	if (n == 0 || m == 0)
		return ans;
	suf[m + 1] = 0;
	occupy[m + 1] = 0;
	for (int i = m; i; i--)
	{
		int pos = lower_bound(v1[x].begin(), v1[x].end() - 1, v2[x][i]) - v1[x].begin();
		if (v1[x][pos] == v2[x][i])
			occupy[i] = 1;
		else
			occupy[i] = 0;
		suf[i] = suf[i + 1] + occupy[i];
	}
	for (int i = 1; i <= m; i++)
	{
		int cur = suf[i + 1], cnt = 0;
		// cout<<"cur="<<cur<<endl;
		int p = lower_bound(v1[x].begin(), v1[x].end() - 1, v2[x][i]) - v1[x].begin();
		if (v1[x][p] <= v2[x][i])
			cnt = p;
		else if (v1[x][p] > v2[x][i])
			cnt = p - 1;
		// cout<<"cnt="<<cnt<<endl;
		int l = v2[x][i] - cnt + 1, r = v2[x][i];
		if (l <= r)
		{
			int pos = lower_bound(v2[x].begin(), v2[x].end() - 1, l) - v2[x].begin();
			// cout<<"l="<<l<<",r="<<r<<endl;
			if (v2[x][pos] >= l)
				cur += i - pos + 1;
		}
		ans = max(ans, cur);
	}
	// cout << ans << endl;
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
	freopen("1.txt", "r", stdin);
#endif
	int T;
	cin >> T;
	while (T--)
	{
		int n, m;
		cin >> n >> m;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		for (int i = 1; i <= m; i++)
			cin >> b[i];
		sort(a + 1, a + n + 1);
		sort(b + 1, b + m + 1);
		int p = lower_bound(a + 1, a + n + 1, 0) - a;
		int q = lower_bound(b + 1, b + m + 1, 0) - b;
		for (int i = 0; i < 2; i++)
			v1[i].clear(), v2[i].clear(), v1[i].push_back(0), v2[i].push_back(0);
		for (int i = p; i <= n; i++)
			v1[0].push_back(a[i]);
		for (int i = p - 1; i; i--)
			v1[1].push_back(-a[i]);
		for (int i = q; i <= m; i++)
			v2[0].push_back(b[i]);
		for (int i = q - 1; i; i--)
			v2[1].push_back(-b[i]);
		for (int i = 0; i < 2; i++)
			v1[i].push_back(0x3f3f3f3f), v2[i].push_back(0x3f3f3f3f);
		int ans = 0;
		for (int i = 0; i < 2; i++)
			ans += solve(i);
		cout << ans << endl;
	}
}