#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long y = 0; y < t; y++) {
    long long n, m, count, odd = 0, even = 0, even1 = 0, odd1 = 0;
    cin >> n;
    long long p[n];
    for (long long i = 0; i < n; i++) {
      cin >> p[i];
      if (p[i] % 2 == 0)
        even++;
      else
        odd++;
    }
    cin >> m;
    int q[m];
    for (long long j = 0; j < m; j++) {
      cin >> q[j];
      if (q[j] % 2 == 0)
        even1++;
      else
        odd1++;
    }
    count = even1 * even + odd1 * odd;
    cout << count << endl;
  }
}
