#include <bits/stdc++.h>
using namespace std;
int q, n, m, x;
long long ml, nl, mc, nc;
map<int, int> M;
int main() {
  cin >> q;
  for (int t = 1; t <= q; t++) {
    cin >> n;
    M.clear();
    mc = ml = nc = nl = 0;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      if (M[x] != 0) continue;
      if (x % 2 == 0)
        nl++;
      else
        nc++;
      M[x]++;
    }
    M.clear();
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> x;
      if (M[x] != 0) continue;
      if (x % 2 == 0)
        ml++;
      else
        mc++;
      M[x]++;
    }
    long long res = 0;
    if (ml != 0 && nl != 0) res = ml * nl;
    if (nc != 0 && mc != 0) res += nc * mc;
    cout << res << endl;
  }
}
