#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
const int modn = 1e9+7;
int a[maxn],b[maxn];
map<int,int> mp,mp2;
int binaryl(int value,int l,int r){
    int res = l-1;
    while(r >= l){
        int mid = (r+l) >> 1;
        if(b[mid] < value){
            res = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    return res;
}
int binaryr(int value,int l,int r){
    int res = r + 1;
    while(r >= l){
        int mid = (r+l) >> 1;
        if(b[mid] > value){
            res = mid;
            r = mid-1;
        }
        else l = mid+1;
    }
    return res;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        mp.clear();
        mp2.clear();
        int n,m;
        scanf("%d%d",&n,&m);
        int midn = n+1,midm = m+1;
        for(int i = 1;i <= n;i++){
            scanf("%d",&a[i]);
            mp[a[i]] = 1;
            if(midn == n+1 && a[i] > 0)midn = i;
        }
        for(int j = 1;j <= m;j++){
            scanf("%d",&b[j]);
            mp2[b[j]] = 1;
            if(midm == m+1 && b[j] > 0)midm = j;
        }

        int lstart = 0;
        for(int i = 1;i < midm;i++){
            if(mp[b[i]])lstart++;
        }
        int ans1 = lstart,ans2 = 0;
        int now = midn-1;
        int len = 0;
        for(int i = midm-1;i >= 1;i--){
//            printf("%d\n",i);
            int res = lstart;
            int bb = b[i]-len;
            while(now && bb <= a[now]){
                if(mp2[a[now]])res--;
                len++;
                bb--;
                now--;
            }
            if(!len)continue;
            int where = b[i] - len+1;
            where = binaryl(where,1,i);
//            printf("%d: where==%d res==%d len==%d\n",i,where,res,len);
            lstart = res;
            res += i - where;
            ans1 = max(ans1,res);
        }

        int rstart = 0;
        for(int i = midm;i <= m;i++){
            if(mp[b[i]])rstart++;
        }
        ans2 = rstart;
        now = midn;
        len = 0;
        for(int i = midm;i <= m;i++){
            int res = rstart;
            int bb = b[i] + len;
            while(now <= n && bb >= a[now]){
                if(mp2[a[now]])res--;
                len++;
                bb++;
                now++;
            }
            if(len == 0)continue;
            int where = b[i] + len-1;
            where = binaryr(where,i,m);
//            printf("%d: where==%d res==%d len==%d\n",i,where,res,len);
            rstart = res;
            res += where - i;
            ans2 = max(ans2,res);
        }
//        printf("%d %d\n",ans1,ans2);
        printf("%d\n",ans1+ans2);
    }
}
/*
1000
5 5
-5 -3 -1 8 100
-9 -7 -3 1000 1001

1 5
-5
-10 -9 -8 -7 -4

5 5
-5 -4 -3 -2 -1
-100 -99 -96 -95 -94
*/
