#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int odd = 0, even = 0, od = 0, ev = 0;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      if (x & 1)
        odd += 1;
      else
        even += 1;
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
      int x;
      cin >> x;
      if (x & 1)
        od += 1;
      else {
        ev += 1;
      }
    }
    cout << even * 1LL * ev + odd * 1LL * od << endl;
  }
  return 0;
}
