#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m, a, b;
    int ans1[2] = {}, ans2[2] = {};
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> a;
      if (a % 2 == 0) {
        ans1[0]++;
      } else {
        ans1[1]++;
      }
    }
    cin >> m;
    for (int j = 0; j < m; j++) {
      cin >> a;
      if (a % 2 == 0) {
        ans2[0]++;
      } else {
        ans2[1]++;
      }
    }
    cout << ans1[1] * ans2[1] + ans1[0] * ans2[0] << endl;
  }
  return 0;
}
