#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tests;
  cin >> tests;
  for (long long t = 0; t < tests; ++t) {
    long long n;
    cin >> n;
    long long np = 0, nd = 0, mp = 0, md = 0;
    for (long long i = 0; i < n; ++i) {
      long long a;
      cin >> a;
      if (a & 1)
        ++nd;
      else
        ++np;
    }
    long long m;
    cin >> m;
    for (long long i = 0; i < m; ++i) {
      long long a;
      cin >> a;
      if (a & 1)
        ++md;
      else
        ++mp;
    }
    cout << ((np * mp) + (nd * md)) << endl;
  }
}
