#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cstdio>
#include <vector>          
#include <assert.h>
#include <unordered_set>
#include <cmath>
#include <ctime>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <map>
#include <numeric>
#include <set>

#define pb push_back
#define deb(x) cerr << #x << " = " << x << " "
#define debe(x) cerr << #x << " = " << x << "\n"
#define pii pair <int, int> 
#define F first
#define S second

using namespace std;

typedef long long ll;

const int N = int(3e5);
const ll MOD = 1e9 + 7;
const ll inf = ll(8e18);  
const int INF = int(2e9);

unordered_map <int, bool> special;
int pref[N];

int Greedy(vector <int> a, vector <int> b) {
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  special.clear();
  for (int i : b) {
    special[i] = true;
  } 
  for (int i = 0; i <=a.size(); i++) pref[i] = 0;
  int cnt = 0;

  for (int i = (int)a.size() - 1; i >= 0; i--) {
    pref[i] = pref[i + 1] + (special[a[i]]);
  }
  int ans = cnt;
  int l = 0;
  queue <int> q;
  a.push_back(INF);
  for (int i = 0; i < a.size(); i++) {
    int maxGroup = 0;
    while (l < (int)b.size() && b[l] < a[i]) {
      q.push(b[l]);
      while (!q.empty() && q.front() + i - 1 < b[l]) q.pop();
      maxGroup = max(maxGroup, int(q.size()));
      l++; 
    }
    while (!q.empty() && q.front() < a[i] - i) q.pop();
    ans = max(ans, pref[i] + maxGroup);
  }
  return ans;
}

void solve() {
  int n, m;
  cin >> n >> m;
  int a[n + 1], b[m + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  vector <int> vap, vbp, van, vbn;
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0) 
      vap.pb(a[i]);
    else 
      van.pb(-a[i]);
  }
  for (int i = 1; i <= m; i++) {
    if (b[i] > 0) 
      vbp.pb(b[i]);
    else 
      vbn.pb(-b[i]);
  }
  cout << Greedy(vap, vbp)+ Greedy(van, vbn) <<endl;;
}
int main () {
  int test;
  cin >> test;
  // test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
