#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, m12 = 0, m22 = 0, m11 = 0, m21 = 0, x, n, m;
  cin >> t;
  while (t--) {
    cin >> n;
    while (n--) {
      cin >> x;
      if (x % 2 == 0)
        m12++;
      else
        m11++;
    }
    cin >> m;
    while (m--) {
      cin >> x;
      if (x % 2 == 0)
        m22++;
      else
        m21++;
    }
    cout << m12 * m22 + m11 * m21 << "\n";
    m12 = 0;
    m22 = 0;
    m11 = 0;
    m21 = 0;
  }
  return 0;
}
