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

const int N = 2e5 + 10;

vector<int> a1, a2, b1, b2;
int suf1[N], suf2[N];
int n, m;

inline void init() {
	a1.clear();
	a2.clear();
	b1.clear();
	b2.clear(); 
	for(int i = 0; i <= m + 5; ++ i) {
		suf1[i] = suf2[i] = 0;
	}
}

inline void getNum(const vector<int>& a, const vector<int>& b, int suf[]) {
	if(a.size() == 0 || b.size() == 0) return;
	int i = b.size() - 1, j = a.size() - 1;
	int cnt = 0;
	while(i >= 0) {
		while(a[j] > b[i] && j > 0) --j;
		if(a[j] == b[i]) ++suf[i];
		--j, --i;
		if(j < 0) break;
	}
	int siz = b.size();
	for(int i = siz - 1; i >= 0; --i) {
		suf[i] += suf[i + 1];
	} 
}

int getAns(const vector<int>& a, const vector<int>& b, int suf[]) {
	if(a.size() == 0 || b.size() == 0) return 0;
	int ans = 0;
	int siz = b.size();
	for(int i = siz - 1; i >= 0; -- i) {
		int res = suf[i + 1];
		int pos = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
//		--pos;
		if(pos > 0) {
			int l = b[i] - pos + 1;
			int pp = lower_bound(b.begin(), b.end(), l) - b.begin();
			res += i - pp + 1;
		}
		
		ans = max(ans, res);	
	}
	ans = max(ans, suf[0]);
	
	return ans;
}

const int inf = 0x3f3f3f3f;

int p[N];

int solve(vector<int> &a, vector<int> &b) {
    set<int> s;
    for (auto x:b) {
        s.insert(x);
    }
    int mmax = 0;
    int now;
    for (int i = 0; i < a.size(); i++) {
        if (s.count(a[i])) p[i] = 1, mmax++;
        else p[i] = 0;
    }
    now = mmax;
    int posl = 0, posr = 0;
    int num = 0;
    while (posr + 1 < b.size() && b[posr + 1] < a[0]) {
        posl++;
        posr++;
    }
    for (int i = 0; i < (int) a.size() - 1; i++) {
        now -= p[i];
        num++;
        while (posr + 1 < b.size() && b[posr + 1] < a[i + 1]) {
            posr++;
            while (b[posr] - b[posl] + 1 > num) posl++;
            mmax = max(mmax, now + posr - posl + 1);
        }
    }
    return mmax;
}
 

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int T;
	cin >> T;
	while(T--) {
		cin >> n >> m;
		init();
		for(int i = 0, x; i < n; ++ i) {
			cin >> x;
			if(x < 0) a1.push_back(-x);
			else a2.push_back(x);
		}
		for(int i = 0, x; i < m; ++ i) {
			cin >> x;
			if(x < 0) b1.push_back(-x);
			else b2.push_back(x);
		}
		b1.push_back(0); b2.push_back(0); 
		a1.push_back(inf); a2.push_back(inf);
		sort(a1.begin(), a1.end()); sort(a2.begin(), a2.end());
		sort(b1.begin(), b1.end()); sort(b2.begin(), b2.end());
//		getNum(a1, b1, suf1);
//		getNum(a2, b2, suf2);
		
//		for(int i = 0; i < b1.size(); ++ i) {
//			cout << suf1[i] <<" ";
//		}
//		cout << endl;

		int ans = 0;
		
		ans += solve(a1, b1);
		ans += solve(a2, b2);
		
		cout << ans << endl; 
	}
	
	return 0;
} 