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 int MOD = 998244353;
pair<int, int> operator+(const pair<int, int>& A, const pair<int, int>& B) {
  return make_pair(A.first + B.first, A.second + B.second);
}
pair<int, int> operator-(const pair<int, int>& A, const pair<int, int>& B) {
  return make_pair(A.first - B.first, A.second - B.second);
}
long long operator*(const pair<int, int>& A, const pair<int, int>& B) {
  return 1LL * A.first * B.first + 1LL * A.second * B.second;
}
long long operator/(const pair<int, int>& A, const pair<int, int>& B) {
  return -(1LL * A.first * B.second - 1LL * A.second * B.first);
}
int n, m;
pair<int, int> ver[1005];
pair<int, int> A, B;
void init() {
  return;
  int mn = 0;
  for (int i = 0; i < (int)(n); i++)
    if (ver[i] < ver[mn]) mn = i;
  rotate(ver, ver + mn, ver + n);
  for (int i = 1; i <= (int)(n - 1); i++)
    if ((ver[(i + 1) % n] - ver[i]) / (ver[i] - ver[i - 1]) == 0)
      ver[i] = ver[i - 1];
  n = unique(ver, ver + n) - ver;
}
long long tar[1005];
vector<long double> ps;
vector<pair<long double, long double> > is;
double solve() {
  B = B - A;
  for (int i = 0; i < (int)(n); i++) tar[i] = (ver[i] - A) / B;
  ps.clear();
  is.clear();
  for (int i = 0; i < (int)(n); i++) {
    long long t0 = tar[i], t1 = tar[(i + 1) % n];
    pair<int, int> v0 = ver[i], v1 = ver[(i + 1) % n];
    if (t0 == 0 && t1 == 0)
      is.push_back(make_pair((v0 - A) * B * (long double)1,
                             (v1 - A) * B * (long double)1));
    else if ((t0 >= 0 && t1 < 0) || (t0 < 0 && t1 >= 0))
      ps.push_back(
          ((v0 - A) * B * (long double)t1 - (v1 - A) * B * (long double)t0) /
          (t1 - t0));
  }
  for (int i = 0; i < (int)(is.size()); i++)
    if (is[i].first > is[i].second) swap(is[i].first, is[i].second);
  sort(ps.begin(), ps.end());
  for (int i = 0; i < (int)ps.size(); i += 2)
    is.push_back(make_pair(ps[i], ps[i + 1]));
  sort(is.begin(), is.end());
  for (int i = 0; i < (int)(is.size()); i++)
    if (i != 0) is[i].second = max(is[i].second, is[i - 1].second);
  long double ans = 0;
  for (int i = 0; i < (int)(is.size()); i++)
    ans += i == 0 || is[i].first > is[i - 1].second
               ? is[i].second - is[i].first
               : is[i].second - is[i - 1].second;
  return ans / sqrt(B * B);
}
void getp(pair<int, int>& A) {
  double x, y;
  scanf("%lf%lf", &x, &y);
  x *= 100;
  y *= 100;
  x += x > 0 ? 0.5 : -0.5;
  y += y > 0 ? 0.5 : -0.5;
  A = make_pair(x, y);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); i++) getp(ver[i]);
  init();
  for (int i = 0; i < (int)(m); i++) {
    getp(A);
    getp(B);
    printf("%.10lf\n", solve() / 100);
  }
  return 0;
}