#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int MAXN = 1e5 + 10;
const double eps = 1e-12;

struct vec {
    double x, y;
    double p;
    vec() {}
    vec(double a, double b)
    {
        x = a, y = b;
    }
    vec operator*(const vec& i_T) const
    {
        return vec(x * i_T.x, y * i_T.y);
    }
    vec operator*(double u) const
    {
        return vec(x * u, y * u);
    }
    bool operator>(const vec a) const
    {
        return x == a.x ? y > a.y : x > a.x;
    }
    vec operator-(const vec a) const
    {
        return vec(x - a.x, y - a.y);
    }
    vec operator+(const vec a) const
    {
        return vec(x + a.x, y + a.y);
    }
    bool operator<(const vec a) const
    {
        return y == a.y ? x < a.x : y < a.y;
    }
    friend ostream& operator<<(ostream& out, vec& a)
    {
        cout << a.x << ' ' << a.y;
        return out;
    }
    friend istream& operator>>(istream& in, vec& a)
    {
        in >> a.x >> a.y;
        return in;
    }
};
int n;
double chaji(vec A, vec B)
{
    return A.x * B.y - A.y * B.x;
}
double xuanzhuan(vec a, vec b, vec c)
{
    return chaji(b - a, c - a);
}
double dianji(vec A, vec B) //点积
{
    return A.x * B.x + A.y * B.y;
}
double changdu(vec a) //长度
{
    return sqrt(a.x * a.x + a.y * a.y);
}
int zhengfu(double d) //判断正负
{
    if (fabs(d) < eps)
        return 0;
    if (d > 0)
        return 1;
    return -1;
}
int zhixian_xianduan_xiangjiao(vec a, vec b, vec c, vec d) //直线与线段是否有交点
{
    double c1 = chaji(b - a, c - a), d1 = chaji(b - a, d - a);
    if (zhengfu(c1) == 0 && zhengfu(d1) == 0) { //重合
        return -1;
    } else if (zhengfu(c1 * d1) <= 0) //有交点
        return 1;
    return 0; //平行
}
vec touying(vec a, vec b, vec c) //c投影在ab上的位置
{
    vec A = b - a;
    vec B = c - a;
    double La = changdu(A);
    double Lc = dianji(A, B) / (La * La);
    return vec(Lc * A.x, Lc * A.y) + a;
}
vec fanshe(vec a, vec b, vec c) //求c关于ab的对称点c'
{
    vec A = touying(a, b, c);
    return (A - c) * 2.0 + c;
}
vec zhixian_xianduan_jiaodian(vec a, vec b, vec c, vec d) //直线与线段的交点
{
    vec ret;
	ret.x = ((b.x-a.x)*(c.y*(d.x-c.x)+c.x*(c.y-d.y))-(d.x-c.x)*(a.y*(b.x-a.x)+a.x*(a.y-b.y)))/((b.y-a.y)*(d.x-c.x)-(d.y-c.y)*(b.x-a.x));
	if(a.x != b.x){
		ret.y = ((b.y-a.y)*ret.x+a.y*(b.x-a.x)+a.x*(a.y-b.y))/(b.x-a.x);
	}else{
		ret.y = ((d.y-c.y)*ret.x+c.y*(d.x-c.x)+c.x*(c.y-d.y))/(d.x-c.x);
	}
	return ret;
}
vec p[MAXN];
double duobianxingmianji(int n) //多边形面积
{
    double ans = 0;
    p[0] = p[n];
    for (int i = 0; i < n; i++)
        ans += chaji(p[i], p[i + 1]);
    ans = fabs(ans) * 0.5;
    return ans;
}
vec q[MAXN];
void qiegetubao(vec p1, vec p2)
{
    int tail = 0;
    q[0] = q[n];
    int tf = -1, x;
    for (int i = 0; i < n; i++) {
        if (zhengfu(xuanzhuan(p1, p2, q[i])) == 1)
            p[++tail] = q[i];
        int f = zhixian_xianduan_xiangjiao(p1, p2, q[i], q[i + 1]);

        if (f == 1) {
            tf = 1;
            p[++tail] = zhixian_xianduan_jiaodian(p1, p2, q[i], q[i + 1]);
        } else if (f == -1) {
            tf = 0;
            x = i;
            break;
        }
    }
    if (tf == 0) {
        //cout<<q[x+1]<<' '<<q[x]<<' '<<endl;
        if (zhengfu(dianji(p2 - p1, q[x + 1] - q[x])) == -1)
            printf("%.8f\n", 0.0);
        else {
            for (int i = 1; i <= n; i++)
                p[i] = q[i];
            printf("%.8f\n", duobianxingmianji(n));
        }
    } else {
        /*for (int i = 1; i <= tail; i++)
            cout << p[i] << endl;*/
        printf("%.8f\n", duobianxingmianji(tail));
    }
    q[0] = vec(0, 0);
}
int main()
{
    //freopen("txt.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> q[i];
    int t;
    cin >> t;
    while (t--) {
        vec p1, p2;
        cin >> p1 >> p2;
        memset(p, 0, sizeof(p));
        qiegetubao(p1, p2);
    }
    return 0;
}
/*
4
-57 5
52 -44
69 32
8 93
1
16 -88 42 -75

*/
