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