#include <bits/stdc++.h>
using namespace std;
int t, n, x, cnt_0[2], cnt_1[2];
void read(int* a) {
  fill(a, a + 2, 0);
  cin >> n;
  while (n--) {
    cin >> x;
    a[x & 1]++;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> t;
  while (t--) {
    read(cnt_0);
    read(cnt_1);
    cout << 1LL * cnt_0[0] * cnt_1[0] + 1LL * cnt_0[1] * cnt_1[1] << '\n';
  }
  return 0;
}
