#include <bits/stdc++.h>
using namespace std;

int t;

int calc(vector<int> &a, vector<int> &b) {
	int n = a.size();
	int m = b.size();
	vector<int> suff(n + 1);
	int r = m - 1;
	for (int i = n - 1; i >= 0; i--) {
		suff[i] = suff[i + 1];
		while (r >= 0 && b[r] > a[i]) r--;
		if (r >= 0 && b[r] == a[i]) suff[i]++;
	}
	int res = 0;
	int j = 0;
	r = 0;
	for (int i = 0; i < m; i++) {
		while (j < n && a[j] <= b[i] + j) {
			j++;
		}
		while (r < m && b[r] - b[i] < j) {
			r++;
		}
		res = max(res, r - i + suff[j]);
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		vector<int> a, b;
		a.resize(n);
		b.resize(m);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < m; i++) {
			cin >> b[i];
		}
		vector<int> al, ar, bl, br;
		for (int i = 0; i < n; i++) {
			if (a[i] < 0) {
				al.push_back(-a[i]);
			} else {
				ar.push_back(a[i]);
			}
		}
		for (int i = 0; i < m; i++) {
			if (b[i] < 0) {
				bl.push_back(-b[i]);
			} else {
				br.push_back(b[i]);
			}
		}
		reverse(bl.begin(), bl.end());
		reverse(al.begin(), al.end());
		cout << calc(al, bl) + calc(ar, br) << '\n';
	}
	return 0;
}