#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 3;
int cnt1, cnt2;
inline int read() {
  int x = 0;
  bool f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return f ? -x : x;
}
int main() {
  int T = read();
  while (T--) {
    int n = read();
    cnt1 = cnt2 = 0;
    for (register int i = (1), i_end = (n); i <= i_end; ++i) {
      if (read() & 1)
        cnt1++;
      else
        cnt2++;
    }
    int m = read();
    long long ans = 0;
    for (register int i = (1), i_end = (m); i <= i_end; ++i) {
      if (read() & 1)
        ans += cnt1;
      else
        ans += cnt2;
    }
    cout << ans << endl;
  }
  return 0;
}
