#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int p[n + 5];
    long long pp[5] = {0};
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      pp[p[i] % 2]++;
    }
    int m;
    cin >> m;
    int q[m + 5];
    long long pq[5] = {0};
    for (int i = 0; i < m; i++) {
      cin >> q[i];
      pq[q[i] % 2]++;
    }
    long long ans = pp[0] * pq[0] + pp[1] * pq[1];
    cout << ans << endl;
  }
}
