#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n;
    long long a, b, c, d;
    a = b = c = d = 0;
    while (n--) {
      int tmp;
      cin >> tmp;
      if (tmp & 1)
        a++;
      else
        b++;
    }
    cin >> m;
    while (m--) {
      int tmp;
      cin >> tmp;
      if (tmp & 1)
        c++;
      else
        d++;
    }
    cout << a * c + b * d << endl;
  }
  return 0;
}
