#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    std::vector<ll> v(n);
    ll oddn = 0;
    ll evenn = 0;
    for (ll i = 0; i < n; ++i) {
      cin >> v[i];
      if (v[i] % 2) {
        oddn++;
      } else {
        evenn++;
      }
    }
    ll m;
    cin >> m;
    std::vector<ll> u(m);
    ll oddm = 0;
    ll evenm = 0;
    for (ll i = 0; i < m; ++i) {
      cin >> u[i];
      if (u[i] % 2) {
        oddm++;
      } else {
        evenm++;
      }
    }
    cout << oddn * oddm + evenm * evenn << "\n";
  }
  return 0;
}
