Problem: Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon.

The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles.

Input

The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct.

The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates.

All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values.

Output

Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input

4 3
0 0
1 0
1 1
0 1
0 0 1 1
0 0 0 1
0 0 1 -1


Output

1.41421356237309514547
1.00000000000000000000
0.00000000000000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const long double PI = acos(-1);
struct pnt {
  long double x, y;
  pnt(long double x = 0, long double y = 0) : x(x), y(y) {}
  pnt operator-(const pnt &p) const { return pnt(x - p.x, y - p.y); }
  pnt operator+(const pnt &p) const { return pnt(x + p.x, y + p.y); }
  pnt operator*(long double p) const { return pnt(x * p, y * p); }
  pnt operator/(long double p) const { return pnt(x / p, y / p); }
  long double operator&(const pnt &p) const { return x * p.x + y * p.y; }
  long double operator^(const pnt &p) const { return x * p.y - y * p.x; }
  inline long double dist() { return sqrt(x * x + y * y); }
  void input() {
    double xx, yy;
    scanf("%lf %lf", &xx, &yy);
    x = (long double)xx, y = (long double)yy;
  }
  void print() { printf("%lf %lf\n", (double)x, (double)y); }
} p[1005];
int n;
bool inside(pnt a, pnt b, pnt c) {
  long double A = a - b & a - c;
  long double B = a - b ^ a - c;
  if (fabs(B) > EPS) return 0;
  return A <= 0;
}
int intersect(pnt a, pnt b, pnt c, pnt d, pnt &res) {
  if (fabs(b - a ^ d - c) < EPS) {
    if (fabs(b - c ^ a - c) < EPS) return -1;
    return 0;
  }
  long double chk1 = b - a ^ c - a;
  long double chk2 = b - a ^ d - a;
  if (chk1 > EPS && chk2 > EPS) return 0;
  if (chk1 < EPS && chk2 < EPS) return 0;
  long double s1 = b - a ^ d - c, s2 = b - c ^ a - c;
  long double s = s2 / s1;
  res = c + ((d - c) * s);
  return 1;
}
long double sto[1005];
pair<long double, long double> V[1005];
int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) p[i].input();
  while (m--) {
    pnt a, b;
    a.input(), b.input();
    int cnt = 0, cv = 0;
    long double len = (b - a & b - a);
    for (int i = 0; i < n; i++) {
      pnt tp;
      int chk = intersect(a, b, p[i], p[(i + 1) % n], tp);
      if (chk > 0) {
        sto[cnt++] = (tp - a & b - a) / len;
      } else if (chk < 0) {
        long double x = (p[i] - a & b - a) / len;
        long double y = (p[(i + 1) % n] - a & b - a) / len;
        if (x > y) swap(x, y);
        V[cv++] = pair<long double, long double>(x, y);
      }
    }
    sort(sto, sto + cnt);
    for (int i = 0; i + 1 < cnt; i += 2)
      V[cv++] = pair<long double, long double>(sto[i], sto[i + 1]);
    sort(V, V + cv);
    long double rlt = 0, cur = -(1e18);
    len = sqrt(len);
    for (int i = 0; i < cv; i++) {
      if (cur < V[i].first) cur = V[i].first;
      if (cur < V[i].second) rlt += V[i].second - cur, cur = V[i].second;
    }
    printf("%.15lf\n", (double)(rlt * len));
  }
}