#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tc, n, arr1[100005], m, arr2[100005], count = 0, even = 0,
                                                  even2 = 0, odd = 0, odd2 = 0;
  cin >> tc;
  while (tc--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> arr1[i];
      if (arr1[i] % 2 == 0)
        even++;
      else
        odd++;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> arr2[i];
      if (arr2[i] % 2 == 0)
        even2++;
      else
        odd2++;
    }
    count += even * even2;
    count += odd * odd2;
    cout << count << endl;
    count = 0;
    even = 0;
    even2 = 0;
    odd = 0;
    odd2 = 0;
  }
}
