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

int solve(int i, int n, int j, int m, vector<int>& a, vector<int>& b){
    if(i >= n || j >= m) return 0;
    if(a[i] < 0){
        reverse(a.begin() + i, a.begin() + n);
        reverse(b.begin() + j, b.begin() + m);
    }
    int cnt = 0;
    vector<int> upto, already(m - j);
    unordered_set<int> s;
    for(int x = i; x < n; x++) s.insert(abs(a[x]));
    for(int x = 0; x < m - j; x++){
        if(s.count(abs(b[x + j]))) already[x] = 1;
    }
    for(int x = m - j - 2; x >= 0; x--)
        already[x] += already[x + 1];
    int I= i, J = j;
    // for(int x = j; x < m; x++) cout << abs(b[x]) << " ";
    // cout << endl;
    for(;i < n && j < m; j++){
        while(i < n && abs(a[i]) <= abs(b[j])){
            i++; cnt++;
        }
        upto.push_back(cnt);
    }
    while(j < m){
        upto.push_back(cnt);
        j++;
    }
    // for(int i : upto) cout << i << " ";
    // cout << endl;
    int ans = 0;
    for(int r = J, l = J; r < m; r++){
        while(l <= r && (abs(b[r]) - abs(b[l]) + 1) > upto[r - J]) l++;
        // cout << r - l + 1 << " " << already[r + 1 - J] << endl;
        ans = max(ans, r - l + 1 + ((r + 1 - J < already.size()) ? already[r + 1 - J] : 0));
    }
    // cout << endl;
    return ans;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int m, n;
        cin >> n >> m;
        vector<int> a(n), b(m);
        for(int i = 0; i < n; i++) cin >> a[i];
        for(int j = 0; j < m; j++) cin >> b[j];
        int za, zb;
        for(za = 0; za < n && a[za] < 0; za++);
        for(zb = 0; zb < m && b[zb] < 0; zb++);
        int ans = solve(0, za, 0, zb, a, b);
        ans += solve(za, n, zb, m, a, b);
        cout << ans << "\n";
    }
    return 0;
}