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;
template <class T>
inline void read(T &num) {
  num = 0;
  bool f = true;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = false;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    num = num * 10 + ch - '0';
    ch = getchar();
  }
  num = f ? num : -num;
}
int out[100];
template <class T>
inline void write(T x, char ch) {
  if (x == 0) {
    putchar('0');
    putchar(ch);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int num = 0;
  while (x) {
    out[num++] = (x % 10);
    x = x / 10;
  }
  for (int i = (num - 1); i >= (0); i--) putchar(out[i] + '0');
  putchar(ch);
}
const int N = 1005;
const double eps = 1e-5;
int n, m;
struct Point {
  double x, y;
  double length() { return sqrt(x * x + y * y); }
} a[N];
Point operator-(const Point &a, const Point &b) {
  return {a.x - b.x, a.y - b.y};
}
double cross(Point a, Point b) { return a.x * b.y - b.x * a.y; }
struct L {
  double l;
  int v;
} stk[N];
int top;
bool cmp(L a, L b) { return a.l < b.l; }
double Len(Point a, Point v, Point p, Point q) {
  return cross(p - a, q - p) / cross(v, q - p);
}
int sign(double x) {
  if (x < -eps) return -1;
  if (x > eps) return 1;
  return 0;
}
double solve(Point p, Point v) {
  top = 0;
  for (int i = (1); i <= (n); i++) {
    int s1 = sign(cross(v, a[i - 1] - p));
    int s2 = sign(cross(v, a[i] - p));
    if (s1 > 0 && s2 > 0 || s1 == 0 && s2 == 0 || s1 < 0 && s2 < 0) continue;
    if (s1 > s2)
      stk[++top] = {Len(p, v, a[i - 1], a[i]), (s1 != 0 && s2 != 0 ? 2 : 1)};
    else
      stk[++top] = {Len(p, v, a[i - 1], a[i]), (s1 != 0 && s2 != 0 ? -2 : -1)};
  }
  sort(stk + 1, stk + top + 1, cmp);
  double ret = 0;
  int tmp = 0;
  for (int i = 1; i <= top; i++) {
    if (tmp) ret += stk[i].l - stk[i - 1].l;
    tmp += stk[i].v;
  };
  return ret * v.length();
}
int main() {
  read(n);
  read(m);
  for (int i = (1); i <= (n); i++) scanf("%lf%lf", &a[i].x, &a[i].y);
  a[0] = a[n];
  for (int j = (1); j <= (m); j++) {
    Point p, q;
    scanf("%lf%lf", &p.x, &p.y);
    scanf("%lf%lf", &q.x, &q.y);
    printf("%.10f\n", solve(p, q - p));
  }
}