#include <bits/stdc++.h>
using namespace std;
long long p, q;
int main() {
  int t, n, m;
  long long res = 0;
  long long evenp = 0, oddp = 0, evenq = 0, oddq = 0;
  cin >> t;
  for (int k = 0; k < t; k++) {
    cin >> n;
    res = 0;
    evenp = 0;
    oddp = 0;
    evenq = 0;
    oddq = 0;
    for (int i = 0; i < n; i++) {
      cin >> p;
      if (p % 2 == 0)
        evenp++;
      else
        oddp++;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> q;
      if (q % 2 == 0)
        evenq++;
      else
        oddq++;
    }
    cout << (evenp * evenq) + (oddp * oddq) << endl;
  }
  return 0;
}
