#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n + 5];
    for (long long i = 0; i < n; i++) cin >> a[i];
    cin >> m;
    long long b[m + 5], ans = 0, cnt = 0, cntt = 0;
    for (long long i = 0; i < m; i++) cin >> b[i];
    for (long long i = 0; i < n; i++) {
      if (a[i] & 1) cnt++;
    }
    for (long long i = 0; i < m; i++)
      if (b[i] & 1) cntt++;
    ans = (n * m) - (cnt * (m - cntt) + (cntt * (n - cnt)));
    cout << ans << endl;
  }
  return 0;
}
