#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;

bool debug = false;
const int NIL = -1;
const int INF = 1000000000;
const int NUM = 100010;
const double eps = 1e-10;
clock_t START, END;

//basic defitition
struct Point {
	double x, y;
	Point(double x = 0, double y = 0) :x(x), y(y) {}
};
typedef Point Vector;
Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Point A, Point B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x * p, A.y * p); }
Vector operator / (Vector A, double p) { return Vector(A.x / p, A.y / p); }
bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
int dcmp(double x) { if (fabs(x) < eps)return 0; else return x < 0 ? -1 : 1; }
bool operator == (const Point& a, const Point& b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; }
// basic operator
double Dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; }
//point and line
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
	Vector u = P - Q;
	double t = Cross(w, u) / Cross(v, w);
	return P + v * t;
}//two lines only have one intersection and Cross(v,w) is not zero
double PolygonArea(vector<Point>& p, int n, int u, int v, Point& X, Point& Y) {
	double area = 0;
	for (int i = u; i % n != v; i++) {
		if (i == n)
			i = 0;
		area += Cross(p[i] - X, p[i + 1] - X);
	}
	area += Cross(p[v] - X, Y - X);
	return area / 2;
}
double ConvexPolygonArea(vector<Point>& p, int n) {
	double area = 0;
	for (int i = 1; i < n; i++) {
		area += Cross(p[i] - p[0], p[i + 1] - p[0]);
	}
	return area / 2;
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in29.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	};
	bool ph = false;
	int n, q, u, v, cnt_s, cnt_l;
	double x, y, _ans;
	vector<Point> p;
	Point p1, p2, X, Y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x, &y);
		p.push_back(Point(x, y));
	}
	p.push_back(p[0]);
	cin >> q;
	for (int i = 0; i < q; i++) {
		scanf("%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y);
		ph = true;
		u = v = -1;
		_ans = 0;
		cnt_s = cnt_l = 0;
		X.x = X.y = Y.x = Y.y = 10001;
		for (int i = 0; i < n; i++) {
			switch ((dcmp(Cross(p2-p1,p[i]-p1)))){
			case 1:cnt_l++; break;
			case -1:cnt_s++; break;
			}
			if (dcmp(Cross(p2 - p1, p[i] - p1)) < 0 && dcmp(Cross(p2 - p1, p[i + 1] - p1)) >= 0) {
				u = i + 1;
				X = GetLineIntersection(p1, p2 - p1, p[i], p[i + 1] - p[i]);
				if (X == p[u])
					u = (u + 1) % n;

			}
			if (dcmp(Cross(p2 - p1, p[i] - p1)) >= 0 && dcmp(Cross(p2 - p1, p[i + 1] - p1)) < 0) {
				v = i;
				Y = GetLineIntersection(p2, p1 - p2, p[i], p[i + 1] - p[i]);
				if (Y == p[v]) {
					if (v == 0)
						v = n - 1;
					else
						v--;
				}
			}
		}
		if (cnt_s == 0)
			_ans = ConvexPolygonArea(p, n);
		else if (cnt_l)
			_ans = PolygonArea(p, n, u, v, X, Y);
		printf("%.8lf\n", _ans);
	}
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


Measured memory_bytes: 3236