#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i <int(n);++i)
#define forsn(i,s,n) for(int i=s;i <int(n);++i)
struct vec {
	double x, y;
	double operator ^ (vec const& o) const {
		return x*o.y - y*o.x;
	}
	double operator * (vec const& o) const {
		return x*o.x + y*o.y;
	}
	vec operator * (double o) const {
		return {x*o , y*o};
	}
	vec operator - (vec const& o) const {
		vec res = *this;
		res.x -= o.x; res.y -= o.y;
		return res;
	}
	vec operator + (vec const& o) const {
		vec res = *this;
		res.x += o.x; res.y += o.y;
		return res;
	}
	double n2 () const {
		return *this * *this;
	}
	double n1 () const {
		return sqrt(n2());
	}
};
using ll = long long;

vec intersect(vec p1, vec q1, vec p2, vec q2){
	vec d1 = q1-p1;
	vec d2 = q2-p2;;
	double alpha = ((d2^p2)-(d2^p1))/(d2^d1);
	return p1+d1*alpha;
}

int main () {
	int n;
	cin >> n;
	vector<vec> ps(n);
	forn(i,n) cin >> ps[i].x >> ps[i].y;
	ps.push_back(ps[0]);
	int q;
	cin >> q;
	forn(i,q){
		vec p1, p2;
		cin >> p1.x >> p1.y >> p2.x >> p2.y;

		auto side = [&](vec p)->int{
			double res = (p2-p1)^(p-p1);
			return (res < 0) ? -1 : (res > 0 ? 1 : 0);
		};

		vector<vec> chiquito;
		forn(i,n){
			int s = side(ps[i]);

			if(s == 1 && side(ps[(i+n-1)%n]) == -1)
				chiquito.push_back(intersect(p1,p2, ps[i],ps[(i+n-1)%n]));

			if(s >= 0) chiquito.push_back(ps[i]);

			if(s == 1 && side(ps[(i+n+1)%n]) == -1)
				chiquito.push_back(intersect(p1,p2, ps[i],ps[(i+n+1)%n]));
		}

		double res = 0;
		// cerr << "<@@\n";
		forn(i,chiquito.size()){
			// cerr << chiquito[i].x << ' ' << chiquito[i].y << '\n';
			res += (chiquito[i]^chiquito[(i+1)%chiquito.size()])/2;
		}
		// cerr << "@@>\n";
		printf("%.9f\n",res);
	}
}
