#include <bits/stdc++.h>
using namespace std;
long long nrimp1, nrimp2, nrpar1, nrpar2;
long long t, n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  for (int l = 1; l <= t; l++) {
    cin >> n;
    int p, q;
    nrpar1 = 0;
    nrimp1 = 0;
    nrpar2 = 0;
    nrimp2 = 0;
    for (int i = 1; i <= n; i++) {
      cin >> p;
      if (p % 2 == 0) nrpar1++;
      if (p % 2 == 1) nrimp1++;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> q;
      if (q % 2 == 0) nrpar2++;
      if (q % 2 == 1) nrimp2++;
    }
    cout << nrpar1 * nrpar2 + nrimp1 * nrimp2 << '\n';
  }
  return 0;
}
