/*
  [BAPC'06] GEODES
  by: Jan Kuipers
*/

using namespace std;

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

typedef vector<double> VD;

VD scan (VD x, VD z, VD z2) {
  int N=x.size(), N2=z2.size();
  int i=0;

  while (!(z[i]==z2[0] && z[(i+1)%N]>z2[0])) i=(i+1)%N;

  rotate(x.begin(),x.begin()+i,x.end());
  rotate(z.begin(),z.begin()+i,z.end());

  VD res(N2);

  i=0;
  for (int j=0; j<N2; j++) {
    while (z2[j]>z[(i+1)%N]) i=(i+1)%N;
    int i2=(i+1)%N;
    res[j]=((z[i]-z2[j])*x[i2]+(z2[j]-z[i2])*x[i])/(z[i]-z[i2]);
  }

  return res;
}

int main () {

  int runs;
  cin>>runs;

  while (runs--) {

    int N1;
    cin>>N1;
    VD x1(N1),z1(N1);
    for (int i=0; i<N1; i++) cin>>x1[i]>>z1[i];

    int N2;
    cin>>N2;
    VD y2(N2),z2(N2);
    for (int i=0; i<N2; i++) cin>>y2[i]>>z2[i];

    VD z;
    for (int i=0; i<N1; i++) z.push_back(z1[i]);
    for (int i=0; i<N2; i++) z.push_back(z2[i]);

    sort(z.begin(),z.end());
    z.erase(unique(z.begin(),z.end()),z.end());
    int N=z.size();

    VD xmin = scan (x1,z1,z);
    VD ymin = scan (y2,z2,z);

    reverse(x1.begin(),x1.end());
    reverse(z1.begin(),z1.end());
    reverse(y2.begin(),y2.end());
    reverse(z2.begin(),z2.end());

    VD xmax = scan (x1,z1,z);
    VD ymax = scan (y2,z2,z);

    double res=0.0;
    for (int i=0; i<N-1; i++) {
      int i2=(i+1)%N;
      double x1=xmax[i]-xmin[i];
      double y1=ymax[i]-ymin[i];
      double x2=xmax[i2]-xmin[i2];
      double y2=ymax[i2]-ymin[i2];
      double h=z[i2]-z[i];
      res+=h*(2*x1*y1+2*x2*y2+x1*y2+x2*y1)/6;
    }

    printf ("%.12lf\n", res);
  }

  return 0;
}
