#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,k=0,i,y,c=0,d=0,x1=0,x2=0,x3=0,x4=0;
        cin>>n>>m;
        k=m;

        ll a[n],b[m];
        for(i=0;i<n;i++)
            cin>>a[i];
        for(i=0;i<m;i++)
            cin>>b[i];

        map<ll,ll>m1,m2,m3,m4,m5,m6;
        for(i=0;i<m;i++)
        {
            if(b[i]>0)
            {k=i;break;}
        }
        for(i=k;i<m;i++)
        {
            m3[b[i]]=i;
        }
        for(i=k-1;i>=0;i--)
        {
            m4[abs(b[i])]=i;
        }
        k=n;
        for(i=0;i<n;i++)
        {
            if(a[i]>0)
            {k=i;break;}
        }
        for(i=k;i<n;i++)
        {
            m1[a[i]]=i-k+1;
        }
        for(i=n-1;i>=0;i--)
        {
            if(m3.find(a[i])!=m3.end())
                x1++;
            m5[a[i]]=x1;
        }
        for(i=k-1;i>=0;i--)
        {
            m2[abs(a[i])]=abs(i-(k-1))+1;
        }
        for(i=0;i<=k-1;i++)
        {
            if(m4.find(abs(a[i]))!=m4.end())
                x2++;
            m6[abs(a[i])]=x2;
        }
        c=x1;
        d=x2;
        if(m1.size()>0 and m3.size()>0)
        {
            for(auto x:m3)
            {x3=0;
                if(m1.upper_bound(x.first)==m1.end())
                    y=m1.size();
                else
                {
                    auto it=m1.upper_bound(x.first);
                    if(it==m1.begin())
                        continue;
                    y=(it->second)-1;
                    //--it;
                    //auto it2=m5it->first);
                    x3=m5[(it->first)];
                }

                y=x.first-y+1;
                auto it1=m3.lower_bound(y);
                c=max(c,abs(x.second-(it1->second))+1+x3);
            }
        }
        if(m2.size()>0 and m4.size()>0)
        {
            for(auto x:m4)
            {x4=0;
                if(m2.upper_bound(x.first)==m2.end())
                    y=m2.size();
                else
                {
                    auto it=m2.upper_bound(x.first);
                    if(it==m2.begin())
                        continue;
                    y=(it->second)-1;
                    //--it;
                    //auto it2=m6.find(it->first);
                    x4=m6[(it->first)];
                }
                //cout<<x.first<<" "<<y<<" ";
                y=x.first-y+1;
                auto it1=m4.lower_bound(y);
                //cout<<m2.size()<<" "<<x.first<<" "<<y<<" "<<abs(x.second-(it1->second))+1+x4<<"\n";
                d=max(d,abs(x.second-(it1->second))+1+x4);
            }
        }
        cout<<c+d<<"\n";
    }
    return 0;
}