#include <bits/stdc++.h>
using namespace std;
using db = double;
inline void out(db x){
cout << fixed << setprecision(4) << x << "\n";
}
struct Point {
db x, y;
Point (){
x = 0;
y = 0;
}
Point(db _x, db _y) : x(_x), y(_y) {}
bool operator < (const Point &oth) const {
return (x < oth.x || (x == oth.x && y < oth.y));
}
bool operator > (const Point &oth) const {
return (x > oth.x || (x == oth.x && y > oth.y));
}
bool operator == (const Point &oth) const {
return (x == oth.x && y == oth.y);
}
bool operator != (const Point &oth) const {
return (x != oth.x || y != oth.y);
}
};
struct Line {
Point x, y;
Line (Point _x, Point _y) : x(_x), y(_y) {}
};
db cross (Point &A, Point &B, Point &C){
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
db dot (Point &A, Point &B, Point &C){
return (B.x - A.x) * (C.x - A.x) + (B.y - A.y) * (C.y - A.y);
}
bool ccw (Point &A, Point &B, Point &C){
return (cross(A, B, C) > 0);
}
vector<Point> ConvexHull (vector<Point> a){
vector<Point> hull;
sort(a.begin(), a.end());
hull.push_back(a[0]);
for (int i = 1; i < a.size(); ++i){
while (hull.size() > 1 && ccw(hull[hull.size() - 2], hull.back(), a[i])){
hull.pop_back();
}
hull.push_back(a[i]);
}
for (int i = a.size() - 2; i >= 0; --i){
while (hull.size() > 1 && ccw(hull[hull.size() - 2], hull.back(), a[i])){
hull.pop_back();
}
hull.push_back(a[i]);
}
if (a.size() > 1){
hull.pop_back();
}
return hull;
}
bool onSegment (Point &A, Point &B, Point &C){
return (cross(A, B, C) == 0 && dot(C, A, B) <= 0);
}
bool inHull (vector<Point> &hull, Point P){
int n = hull.size();
if (onSegment(hull[0], hull[n - 1], P) || onSegment(hull[0], hull[1], P)){
return true;
}
if (!ccw(hull[0], hull[n - 1], P) && !ccw(hull[1], hull[0], P)){
return false;
}
int l = 1, r = n - 1, id = -1;
while (l <= r){
int m = l + r >> 1;
if (!ccw(hull[0], P, hull[m])){
id = m;
r = m - 1;
} else {
l = m + 1;
}
}
return (onSegment(hull[id - 1], hull[id], P) || ccw(P, hull[id], hull[id - 1]));
}
tuple<db, db, db> getDio (Line A){
int a = A.y.y - A.x.y;
int b = A.x.x - A.y.x;
int c = a * A.x.x + b * A.x.y;
return make_tuple(a, b, c);
}
Point Intersect (Line A, Line B){
auto [a1, b1, c1] = getDio(A);
auto [a2, b2, c2] = getDio(B);
db X = (b2 * c1 - b1 * c2) / (a1 * b2 - b1 * a2);
db Y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
Point Z = Point(X, Y);
if (!onSegment(A.x, A.y, Z) || !onSegment(B.x, B.y, Z)){
return Point(-1, -1);
} else {
// cout << A.x.x << " " << A.x.y << " " << A.y.x << " " << A.y.y << "\n";
// cout << B.x.x << " " << B.x.y << " " << B.y.x << " " << B.y.y << "\n";
// cout << Z.x << " " << Z.y << endl;
return Z;
}
}
void solve (){
int n, m; cin >> n >> m;
db ans = 0;
vector<Point> a(n), b(m);
for (int i = 0; i < n; ++i){
cin >> a[i].x >> a[i].y;
}
for (int i = 0; i < m; ++i){
cin >> b[i].x >> b[i].y;
}
a = ConvexHull(a);
b = ConvexHull(b);
vector<Point> c;
for (auto &X : a){
if (inHull(b, X)){
c.push_back(X);
}
}
for (auto &X : b){
if (inHull(a, X)){
c.push_back(X);
}
}
for (int i = 0; i < n; ++i){
int j = (i + 1) % n;
for (int k = 0; k < m; ++k){
int l = (k + 1) % m;
Point cut = Intersect(Line(a[i], a[j]), Line(b[k], b[l]));
if (cut != Point(-1, -1)){
c.push_back(cut);
}
}
}
if (c.size() == 0){
out(0);
return;
}
c = ConvexHull(c);
for (int i = 0; i < c.size(); ++i){
int j = (i + 1) % c.size();
ans += (db)((c[i].x + c[j].x) * (c[i].y - c[j].y) / (db)(2));
}
out(ans);
}
int32_t main (){
ios::sync_with_stdio(false); cin.tie(nullptr);
if (fopen("ipolygon.inp", "r")){
freopen("ipolygon.inp", "r", stdin);
freopen("ipolygon.out", "w", stdout);
}
int tt; cin >> tt;
while (tt--){
solve();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ludCAmQSwgUG9pbnQgJkIsIFBvaW50ICZDKXsKICAgIHJldHVybiAoY3Jvc3MoQSwgQiwgQykgPT0gMCAmJiBkb3QoQywgQSwgQikgPD0gMCk7Cn0KCmJvb2wgaW5IdWxsICh2ZWN0b3I8UG9pbnQ+ICZodWxsLCBQb2ludCBQKXsKICAgIGludCBuID0gaHVsbC5zaXplKCk7CiAgICBpZiAob25TZWdtZW50KGh1bGxbMF0sIGh1bGxbbiAtIDFdLCBQKSB8fCBvblNlZ21lbnQoaHVsbFswXSwgaHVsbFsxXSwgUCkpewogICAgICAgIHJldHVybiB0cnVlOwogICAgfQogICAgaWYgKCFjY3coaHVsbFswXSwgaHVsbFtuIC0gMV0sIFApICYmICFjY3coaHVsbFsxXSwgaHVsbFswXSwgUCkpewogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KICAgIGludCBsID0gMSwgciA9IG4gLSAxLCBpZCA9IC0xOwogICAgd2hpbGUgKGwgPD0gcil7CiAgICAgICAgaW50IG0gPSBsICsgciA+PiAxOwogICAgICAgIGlmICghY2N3KGh1bGxbMF0sIFAsIGh1bGxbbV0pKXsKICAgICAgICAgICAgaWQgPSBtOwogICAgICAgICAgICByID0gbSAtIDE7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbCA9IG0gKyAxOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAob25TZWdtZW50KGh1bGxbaWQgLSAxXSwgaHVsbFtpZF0sIFApIHx8IGNjdyhQLCBodWxsW2lkXSwgaHVsbFtpZCAtIDFdKSk7Cn0KCnR1cGxlPGRiLCBkYiwgZGI+IGdldERpbyAoTGluZSBBKXsKICAgIGludCBhID0gQS55LnkgLSBBLngueTsKICAgIGludCBiID0gQS54LnggLSBBLnkueDsKICAgIGludCBjID0gYSAqIEEueC54ICsgYiAqIEEueC55OwogICAgcmV0dXJuIG1ha2VfdHVwbGUoYSwgYiwgYyk7Cn0KClBvaW50IEludGVyc2VjdCAoTGluZSBBLCBMaW5lIEIpewogICAgYXV0byBbYTEsIGIxLCBjMV0gPSBnZXREaW8oQSk7CiAgICBhdXRvIFthMiwgYjIsIGMyXSA9IGdldERpbyhCKTsKICAgIGRiIFggPSAoYjIgKiBjMSAtIGIxICogYzIpIC8gKGExICogYjIgLSBiMSAqIGEyKTsKICAgIGRiIFkgPSAoYTEgKiBjMiAtIGEyICogYzEpIC8gKGExICogYjIgLSBhMiAqIGIxKTsKICAgIFBvaW50IFogPSBQb2ludChYLCBZKTsKICAgIGlmICghb25TZWdtZW50KEEueCwgQS55LCBaKSB8fCAhb25TZWdtZW50KEIueCwgQi55LCBaKSl7CiAgICAgICAgcmV0dXJuIFBvaW50KC0xLCAtMSk7CiAgICB9IGVsc2UgewovLyAgICAgICAgY291dCA8PCBBLngueCA8PCAiICIgPDwgQS54LnkgPDwgIiAiIDw8IEEueS54IDw8ICIgIiA8PCBBLnkueSA8PCAiXG4iOwovLyAgICAgICAgY291dCA8PCBCLngueCA8PCAiICIgPDwgQi54LnkgPDwgIiAiIDw8IEIueS54IDw8ICIgIiA8PCBCLnkueSA8PCAiXG4iOwovLyAgICAgICAgY291dCA8PCBaLnggPDwgIiAiIDw8IFoueSA8PCBlbmRsOwogICAgICAgIHJldHVybiBaOwogICAgfQp9Cgp2b2lkIHNvbHZlICgpewogICAgaW50IG4sIG07IGNpbiA+PiBuID4+IG07CiAgICBkYiBhbnMgPSAwOwogICAgdmVjdG9yPFBvaW50PiBhKG4pLCBiKG0pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpewogICAgICAgIGNpbiA+PiBhW2ldLnggPj4gYVtpXS55OwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpewogICAgICAgIGNpbiA+PiBiW2ldLnggPj4gYltpXS55OwogICAgfQogICAgYSA9IENvbnZleEh1bGwoYSk7CiAgICBiID0gQ29udmV4SHVsbChiKTsKICAgIHZlY3RvcjxQb2ludD4gYzsKICAgIGZvciAoYXV0byAmWCA6IGEpewogICAgICAgIGlmIChpbkh1bGwoYiwgWCkpewogICAgICAgICAgICBjLnB1c2hfYmFjayhYKTsKICAgICAgICB9CiAgICB9CiAgICBmb3IgKGF1dG8gJlggOiBiKXsKICAgICAgICBpZiAoaW5IdWxsKGEsIFgpKXsKICAgICAgICAgICAgYy5wdXNoX2JhY2soWCk7CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpewogICAgICAgIGludCBqID0gKGkgKyAxKSAlIG47CiAgICAgICAgZm9yIChpbnQgayA9IDA7IGsgPCBtOyArK2spewogICAgICAgICAgICBpbnQgbCA9IChrICsgMSkgJSBtOwogICAgICAgICAgICBQb2ludCBjdXQgPSBJbnRlcnNlY3QoTGluZShhW2ldLCBhW2pdKSwgTGluZShiW2tdLCBiW2xdKSk7CiAgICAgICAgICAgIGlmIChjdXQgIT0gUG9pbnQoLTEsIC0xKSl7CiAgICAgICAgICAgICAgICBjLnB1c2hfYmFjayhjdXQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgaWYgKGMuc2l6ZSgpID09IDApewogICAgICAgIG91dCgwKTsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBjID0gQ29udmV4SHVsbChjKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYy5zaXplKCk7ICsraSl7CiAgICAgICAgaW50IGogPSAoaSArIDEpICUgYy5zaXplKCk7CiAgICAgICAgYW5zICs9IChkYikoKGNbaV0ueCArIGNbal0ueCkgKiAoY1tpXS55IC0gY1tqXS55KSAvIChkYikoMikpOwogICAgfQogICAgb3V0KGFucyk7Cn0KCmludDMyX3QgbWFpbiAoKXsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZShudWxscHRyKTsKICAgIGlmIChmb3BlbigiaXBvbHlnb24uaW5wIiwgInIiKSl7CiAgICAgICAgZnJlb3BlbigiaXBvbHlnb24uaW5wIiwgInIiLCBzdGRpbik7CiAgICAgICAgZnJlb3BlbigiaXBvbHlnb24ub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQogICAgaW50IHR0OyBjaW4gPj4gdHQ7CiAgICB3aGlsZSAodHQtLSl7CiAgICAgICAgc29sdmUoKTsKICAgIH0KfQo=