#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int getnum(const vector<ll>& v, ll x){
  if(x < v[0]) return 0;

  int lb = 0, ub = v.size();
  while(ub-lb>1){
    int mid = (lb+ub)/2;

    if(v[mid] <= x) lb = mid;
    else ub = mid;
  }

  return ub;
}


int calc(const vector<ll>& v, const vector<ll>& w){
  if(v.size() == 0) return 0;
  if(w.size() == 0) return 0;

  map<ll,int> memo;
  rep(i,w.size()){
    memo[w[i]] = i;
  }

  int ret = 0;
  
  int cnt = 0;
  vector<int> match(w.size(), 0);
  rep(i,v.size()){
    if(memo.count(v[i]) > 0){
      cnt++;
      match[memo[v[i]]] = 1;
    }
  }

  ret = max(ret, cnt);

  rep(i,w.size()){
    if(match[i] == 1) cnt--;

    int x = getnum(v, w[i]);
    int y = getnum(w, w[i]);
    int z = getnum(w, w[i]-x);
    
    ret = max(ret, cnt + (y-z));
  }
  
  return ret;
}



void solve(){
  int n, m;
  cin >> n >> m;
  vector<ll> v1, v2, w1, w2;
  rep(i,n){
    ll a;
    cin >> a;
    if(a < 0) v1.push_back(-a);
    else v2.push_back(a);
  }
  reverse(ALLOF(v1));
  
  rep(i,m){
    ll a;
    cin >> a;
    if(a < 0) w1.push_back(-a);
    else w2.push_back(a);
  }
  reverse(ALLOF(w1));
  
  cout << calc(v1,w1) + calc(v2,w2) << endl;
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int t;
  cin >> t;
  rep(i,t){
    solve();
  }
  
  return 0;
}

