#ifdef _LOCAL
#include "debug.h"
#endif
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a1, a2, b1, b2;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x < 0) {
      a1.push_back(-x);
    } else {
      a2.push_back(x);
    }
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    if (x < 0) {
      b1.push_back(-x);
    } else {
      b2.push_back(x);
    }
  }
  sort(a1.begin(), a1.end());
  sort(b1.begin(), b1.end());
  auto solve = [](vector<int> &a, vector<int> &b) {
    a.push_back(2e9);
    vector<int> buf(a.size());
    int p = b.size() - 1;
    for (int i = a.size() - 2; i >= 0; i--) {
      buf[i] = buf[i + 1];
      while (p >= 0 && b[p] > a[i]) {
        p--;
      }
      if (p >= 0 && b[p] == a[i]) {
        buf[i]++;
      }
    }
    int ans = buf[0];
    int j = 0;
    int up = 0;
    for (int i = 0; i < a.size() - 1; i++) {
      while (j < b.size() && b[j] < a[i] - i) {
        j++;
      }
      if (j == b.size()) {
        break;
      }
      int k = j;
      while (k < b.size() && b[k] < a[i + 1] - i - 1) {
        k++;
      }
      for (int t = j; t < k; t++) {
        while (up < b.size() && b[up] - b[t] + 1 <= i + 1) {
          up++;
        }
        ans = max(ans, up - t + buf[i + 1]);
      }
      j = k;
    }
    return ans;
  };
  cout << solve(a1, b1) + solve(a2, b2) << endl;
}

int main() {
  cin.tie(0); cout.sync_with_stdio(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}