//#pragma comment(linker, "/STACK:67108864")
#define _GLIBCXX_DEBUG
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <string>
#include <iomanip>
#include <cstring>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <ctime>
#include <cmath>

using namespace std;

typedef long long ll;

//#define int ll

const int BUBEN = 550;
const int MOD = 1e9 + 7;
const int BASE = 29;

#ifndef _getchar_nolock
char _getchar_nolock() {
    return getchar_unlocked();
}
#endif
 
#ifndef _putchar_nolock
char _putchar_nolock(char i) {
    putchar_unlocked(i);
}
#endif

int f(vector<int> &a, vector<int> &b){
    int n = a.size();
    int m = b.size();
    vector<int> aaa(n + 1);
    int r = m - 1;
    for (int i = n - 1; i >= 0; --i){
        aaa[i] = aaa[i + 1];
        while (r >= 0 && b[r] > a[i])
         --r;
        if (r >= 0 && b[r] == a[i])
         ++aaa[i];
    }
    int ans = 0;
    int j = 0;
    r = 0;
    for (int l = 0; l < m; l++) {
        while (j < n && a[j] <= b[l] + j) ++j;
        while (r < m && b[r] - b[l] < j) ++r;
        ans = max(ans, r - l + aaa[j]);
    }
    return ans;
}

signed main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        vector<int> a1, b1, a2, b2;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            if (x > 0) a2.push_back(x);
            else a1.push_back(-x);
        }
        for (int i = 0 ; i < m; i++) {
            int x;
            cin >> x;
            if (x > 0) b2.push_back(x);
            else b1.push_back(-x);
        }
        reverse(b1.begin(), b1.end());
        reverse(a1.begin(), a1.end());
        cout << f(a2, b2) + f(a1, b1) << '\n';
    }
}