#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-7
using namespace std;
typedef long long ll;
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y - p.y < -EPS;
		else return x - p.x < EPS;
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
	return a.x * b.x + a.y * b.y;
}
double det(Vector a,Vector b){
	return a.x * b.y - b.x * a.y;
}
double area(Polygon p){
	double res = 0.0;
	for(int i=1;i<p.size() - 1;i++){
		res += det(p[i] - p[0],p[i+1] - p[0]) / 2.0;
	}
	return res;
}
vector <int> cwps,ccwps;
Point proj(Point p,Line s){
	double a = dot(p - s.p1,s.p2 - s.p1) / (s.p2 - s.p1).abs_();
	return s.p1 + (s.p2 - s.p1) * (a / (s.p2 - s.p1).abs_());
}
Point cross(Segment s1,Segment s2){
	Point A = proj(s2.p1,s1),B = proj(s2.p2,s1);
	double a = (s2.p1 - A).abs_() / ((s2.p1 - A).abs_() + (s2.p2 - B).abs_());
	return A + (B - A) * a;
}
int ccw(Point p0,Point p1,Point p2){//p2 is at p0p1 ...?
	Vector a = p1 - p0,b = p2 - p0;
	if(det(a,b) > EPS) return 1;//ccw
	if(det(a,b) < -EPS) return -1;//cw
	if(dot(a,b) < -EPS) return 2;//online_back
	if(a.norm() < b.norm()) return -2;//online_front
	return 0;//on_segment
}
int n;
double cut_area(Polygon po,Line l){
	ccwps.clear();
	cwps.clear();
	for(int i=0;i<n;i++){
		int fl = ccw(l.p1,l.p2,po[i]);
		if(fl == 1){
			ccwps.push_back(i);
		}else if(fl == -1) cwps.push_back(i);
	}
	if(ccwps.size() == 0) return 0.0;
	if(cwps.size() == 0) return area(po);
	Polygon q;
	q.clear();
	int m = ccwps.size();
	if(ccwps[0] == 0 && ccwps[m-1] == n-1){
		for(int i=0;i<m;i++){
			q.push_back(po[ccwps[i]]);
			if(i < m-1 && ccwps[i+1] != ccwps[i] + 1){
				int a = ccwps[i],b = ccwps[i+1];
				q.push_back(cross(l,Segment(po[a],po[a+1])));
				q.push_back(cross(l,Segment(po[b-1],po[b])));
			}
		}
	}else{
		int a = ccwps[0];
		q.push_back(cross(l,Segment(po[(a+n-1) % n],po[a])));
		for(int i=0;i<m;i++) q.push_back(po[ccwps[i]]);
		a = ccwps[m-1];
		q.push_back(cross(l,Segment(po[(a+1) % n],po[a])));
	}
	return area(q);
}
Polygon po;
Line l;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		Point p;
		scanf("%lf%lf",&p.x,&p.y);
		po.push_back(p);
  }
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%lf%lf%lf%lf",&l.p1.x,&l.p1.y,&l.p2.x,&l.p2.y);
		printf("%.10f\n",cut_area(po,l));
	}
	return 0;
}



Measured memory_bytes: 3272