Problem: <image>


As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line.

g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n−1) are sides of the convex polygon. The line segment connecting pn and p1 is also a side of the polygon.

Constraints

* 3 ≤ n ≤ 100
* 1 ≤ q ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* -10000 ≤ p1x,p1y,p2x,p2y ≤ 10000
* No point in g will occur more than once.
* p1 ≠ p2

Input

The input is given in the following format:


g (the sequence of the points of the polygon)
q (the number of queries = the number of target lines)
1st query
2nd query
:
qth query


g is given as a sequence of points p1,..., pn in the following format:


n
x1 y1
x2 y2
:
xn yn


The first integer n is the number of points. The coordinate of the i-th point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Note that all interior angles of given convex polygons are less than or equal to 180.

For each query, a line represented by two points p1 and p2 is given. The coordinates of the points are given by four integers p1x, p1y, p2x and p2y.

Output

For each query, print the area of the cut polygon. The output values should be in a decimal fraction with an error less than 0.00001.

Example

Input

4
1 1
4 1
4 3
1 3
2
2 0 2 4
2 4 2 0


Output

2.00000000
4.00000000

Solution (in CPP):

Solution:
#include<iostream>
#include<complex>
#include<vector>
#include<iomanip>
#include<algorithm>

using namespace std;

typedef complex<double> P;
typedef vector<P> G;
#define EPS 1e-9
#define shosu(x) fixed<<setprecision(x)
#define diff(P,i) (P[(i+1)%P.size()] - P[i])

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){;}
};
struct C {
  P c;double r;
  C(const P &c,double r):c(c),r(r){}
};

namespace std{//演算子の定義
  bool operator < (const P& a,const P& b) {
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b) {
    return a.real()==b.real() && a.imag()==b.imag();
  }
}

double dot(P a,P b) {
  return real(conj(a)*b);
}

double cross(P a,P b) {
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c) { //3点の関係性
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;                               // a--c--b on line
}

P projection(const L &l, const P &p) { //pの直線l上の射影の点
  double t=dot(p-l[0],l[0]-l[1])/norm(l[0]-l[1]);
  return l[0]+t*(l[0]-l[1]);
}

P reflection(const L &l, const P &p) { //点pの直線lに関して対称な点
  return p+2.0*(projection(l,p)-p);
}

bool isorthogonal(const L &l, const L &m) { //2直線の直交判定
  return fabs(dot(l[1]-l[0], m[1]-m[0])) < EPS;
}

bool isparallel(const L &l, const L &m) { //2直線の平行判定
  return fabs(cross(l[1]-l[0],m[1]-m[0])) < EPS;
}

bool intersectLL(const L &l, const L &m) { //2直線の交差判定
  return !isparallel(l,m);
}

bool intersectSS(const L &s, const L &t) { //2線分の交差判定(完全に交差してないとだめ)
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

bool intersectSP(const L &s, const P &p) { //直線と点の交差判定
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P crosspointSS(const L &a, const L &b) { //2線分の交点
double t1=abs(cross(a[1]-a[0],b[0]-a[0]));
double t2=abs(cross(a[1]-a[0],b[1]-a[0]));
return b[0]+(b[1]-b[0])*t1/(t1+t2);
}

P crosspointLL(const L &l, const L &m) { //2直線の交点
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}

double distanceSP(const L &s, const P &p) {//直線と点との距離
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

double distanceSS(const L &s, const L &t) {//2線分の距離
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

double area(const G &g) { //多角形の面積
    double S =0;
    for(int i = 0; i < g.size(); i++){
        S +=(cross(g[i],g[(i+1)%g.size()]));
    }
    return abs(S/2.0);
}

bool isconvex(const G &g) { //凸かどうか(全ての内角の大きさが180度以下)
	int n=g.size();
  for(int i = 0; i < n; i++)
    if(ccw(g[(i+n-1)%n],g[i%n],g[(i+1)%n])==-1)return false;
	return true;
}

int inconvex(const G& g, const P& p) { //多角形と点の関係
	bool in = false;
	int n = g.size();
	for(int i = 0; i < n; i++){
		P a=g[i%n]-p;
		P b=g[(i+1)%n]-p;
		if(imag(a)>imag(b))swap(a, b);
		if(imag(a)<EPS&&0<imag(b))if(cross(a,b)<0)in=!in;
		if(abs(cross(a,b))<EPS&&dot(a,b)<EPS)return 1;//ON
	}
	return in?2:0;//IN : OUT;
}

G convex_hull(G &ps) { // 凸包(点集合 P の全ての点を含む最小の凸多角形)
  int n = ps.size(), k = 0;
	sort(ps.begin(), ps.end());
	G ch(2*n);
	for(int i = 0; i < n; ch[k++] = ps[i++])//lower-hull
		while(k >= 2 && ccw(ch[k-2],ch[k-1],ps[i]) == -1) --k;//<=0  ->  ==-1
	for(int i = n-2,t = k+1; i >= 0; ch[k++] = ps[i--])//upper-hull
		while(k >= t && ccw(ch[k-2],ch[k-1],ps[i]) == -1) --k;//
	ch.resize(k-1);
	return ch;
}

double convex_diameter(const G &pt) { //凸多角形の直径(最遠頂点対間距離)
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  double maxd = norm(pt[is]-pt[js]);

  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
    else i = (i+1) % n;
    if (norm(pt[i]-pt[j]) > maxd) {
      maxd = norm(pt[i]-pt[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd); /* farthest pair is (maxi, maxj). */
}//convex_diameter(g)


G convex_cut(const G& g, const L& l) { //凸多角形の切断
  G Q;
  for (int i = 0; i < g.size(); ++i) {
    P a = g[i], b = g[(i+1)%g.size()];
    if (ccw(l[0], l[1], a) != -1) Q.push_back(a);
    if (ccw(l[0], l[1], a)*ccw(l[0], l[1], b) < 0)
      Q.push_back(crosspointLL(L(a,b), l));
  }
  return Q;
}


P inP(){
  double x,y;
  cin >> x >> y;
  P p(x,y);
  return p;
}

L inL(){
  P p1=inP();
  P p2=inP();
  L l(p1,p2);
  return l;
}

int main(){

  int n;
  cin >> n;
  G g;
  for(int i = 0; i< n; i++){
    P p = inP();
    g.push_back(p);
  }
  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    L l = inL();
    cout << shosu(10) << area(convex_cut(g,l)) << endl;
  }
}