#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  long long int n, m;
  vector<long> p, q;
  cin >> t;
  while (t-- > 0) {
    long long int noen = 0, nodn = 0, noem = 0, nodm = 0, temp;
    cin >> n;
    while (n-- > 0) {
      cin >> temp;
      if ((temp % 2 == 0) || (temp == 0))
        noen++;
      else
        nodn++;
    }
    cin >> m;
    while (m-- > 0) {
      cin >> temp;
      if ((temp % 2 == 0) || (temp == 0))
        noem++;
      else
        nodm++;
    }
    cout << (noen * noem) + (nodn * nodm) << endl;
  }
  return 0;
}
