// #pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
using namespace std;

const int N = 2e5 + 10, M = N * 2, INT = 0x3f3f3f3f, mod = 1e9 + 7;

//#define int long long
#define pi 3.1415926
#define x first
#define y second
typedef long long ll;
typedef pair<int,int> pii;
 //ios::sync_with_stdio(false);
ll gcd(ll a,ll b) {return b ? gcd(b, a % b) : a;}
// int gcd(int a,int b) {return b ? gcd(b, a % b) : a;}
ll qmi(ll a,ll b) {ll res = 1 % mod;while (b){if (b & 1) res = (res * a) % mod;a = a * a % mod;b >>= 1;}return res;}

int t, n, m, k;
int x;
deque<int> q1, q2, s1, s2;
int s[M];

int get(deque<int> &a,deque<int> &b)
{
	if (a.size() == 0 || b.size() == 0) return 0;
	s[b.size()] = 0;
	// for (auto x : a) printf("%d ", x);
	// 	puts("");
	// for (auto x : b) printf("%d ", x);
	// 	puts("");
	for (int i = b.size() - 1, j = a.size() - 1; i >= 0; i -- )
	{
		while (a[j] > b[i] && j > 0) j --;
		if (a[j] == b[i]) s[i] = 1;
		else s[i] = 0;
		s[i] += s[i + 1];
	}
	// for (int i = 0; i < b.size(); i ++ ) printf("%d ", s[i]);
	// 	puts("");
	int ans = 0;
	for (int i = 0; i < b.size(); i ++ )
	{
		int p = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
		int l = lower_bound(b.begin(), b.end(), b[i] - p + 1) - b.begin();
		ans = max(ans, s[i + 1] + i - l + 1);
		// printf("b_i=%d p = %d  b_i-p=%d l = %d\n", b[i], p, b[i] - p + 1, l);
	}
	// cout << ans << "-------------------------";
	return ans;
}

void solve()
{
	q1.clear(), q2.clear(), s1.clear(), s2.clear();
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ )
	{
		scanf("%d", &x);
		if (x > 0)
		{
			q1.push_back(x);
		}
		else q2.push_front(-x);
	}
	for (int i = 1; i <= m; i ++ )
	{
		scanf("%d", &x);
		if (x > 0)
		{
			s1.push_back(x);
		}
		else s2.push_front(-x);
	}

	int ans = get(q1, s1) + get(q2, s2);
	// puts("");
	printf("%d\n", ans);
}

signed main()
{
    cin >> t;while (t -- ) 
    solve();
}