#include <bits/stdc++.h>
using namespace std;
long long p, q, p1, q1, n, m, p2, q2, t;
int main() {
  cin >> t;
  while (t--) {
    p1 = p2 = q1 = q2 = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> p;
      if (p % 2)
        p1++;
      else
        p2++;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> q;
      if (q % 2)
        q1++;
      else
        q2++;
    }
    cout << p2 * q2 + p1 * q1 << endl;
  }
  return 0;
}
