#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t, n, m, x;
  long long evenp, evenq, oddp, oddq;
  cin >> t;
  while (t--) {
    evenp = evenq = oddq = oddp = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (x % 2 == 0)
        evenp++;
      else
        oddp++;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> x;
      if (x % 2 == 0)
        evenq++;
      else
        oddq++;
    }
    cout << (evenq * evenp + oddp * oddq) << endl;
  }
  return 0;
}
