#include <bits/stdc++.h>
#pragma GCC optimize "-Ofast"
using namespace std;
const long long mod = 1e9 + 7;
const long long MX = 2e5 + 3;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(12);
  long long t;
  cin >> t;
  for (long long kk = 0; kk < t; kk++) {
    long long n;
    cin >> n;
    long long one = 0, zero = 0;
    for (long long i = 0; i < n; i++) {
      long long temp;
      cin >> temp;
      if (temp % 2)
        zero++;
      else
        one++;
    }
    long long m;
    cin >> m;
    long long one_2 = 0, zero_2 = 0;
    for (long long i = 0; i < m; i++) {
      long long temp;
      cin >> temp;
      if (temp % 2)
        zero_2++;
      else
        one_2++;
    }
    cout << one * one_2 + zero * zero_2 << endl;
  }
  return 0;
}
