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

const int N=200010;
int T,n,m,a[N],b[N];

int cal(vector<int> a,vector<int> b)
{
    if (a.empty() || b.empty()) return 0;
    vector<int> sum;
    int s=0;
    for (int i:a)
    {
        auto it=lower_bound(b.begin(),b.end(),i);
        if (it!=b.end() && *it==i) s++;
        sum.push_back(s);
    }
    int ans=sum.back();
    int siz=a.size(),r=0;
    for (int p:b)
    {
        if (a[0]>p) continue;
        while (r<siz && a[r]<=p+r) r++;
        auto itl=lower_bound(b.begin(),b.end(),p);
        auto itr=upper_bound(b.begin(),b.end(),p+r-1);
        ans=max(ans,(int)(itr-itl)+sum[siz-1]-sum[r-1]);
    }
    return ans;
}

int main()
{
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d",&n,&m);
        for (int i=1;i<=n;i++) scanf("%d",&a[i]);
        for (int i=1;i<=m;i++) scanf("%d",&b[i]);
        int ans=0;
        vector<int> _a,_b;
        for (int i=1;i<=n;i++) if (a[i]>0) _a.push_back(a[i]);
        for (int i=1;i<=m;i++) if (b[i]>0) _b.push_back(b[i]);
        ans+=cal(_a,_b);
        _a.clear(); _b.clear();
        for (int i=n;i>=1;i--) if (a[i]<0) _a.push_back(-a[i]);
        for (int i=m;i>=1;i--) if (b[i]<0) _b.push_back(-b[i]);
        ans+=cal(_a,_b);
        printf("%d\n",ans);
    }
    getchar(); getchar();
    return 0;
}