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 oo = 0x3f3f3f3f;
const long long OO = 0x3f3f3f3f3f3f3f3fLL;
const int M7 = 1000000007;
const int M9 = 1000000009;
const long long M7L = 1000000007L;
template <typename T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <typename T, typename... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <typename T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
template <typename T>
void _W(const vector<T> &x) {
  for (auto i = x.cbegin(); i != x.cend(); i++) {
    if (i != x.cbegin()) putchar(' ');
    _W(*i);
  }
}
void W() {}
template <typename T, typename... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
const int dcmp(const double &x) {
  if (x < -1e-9) return -1;
  return x > 1e-9;
}
inline const double ABS(const double &x) { return (dcmp(x) < 0 ? -x : x); }
inline const double sqr(const double &x) { return x * x; }
struct Point {
  double x, y;
  Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
  const Point operator+(const Point &op) const {
    return Point(x + op.x, y + op.y);
  }
  const Point operator-(const Point &op) const {
    return Point(x - op.x, y - op.y);
  }
  const Point operator*(const double &k) const { return Point(x * k, y * k); }
  const Point operator/(const double &k) const {
    double t = (dcmp(k) ? k : 1);
    return Point(x / t, y / t);
  }
  const double operator*(const Point &op) const {
    return (x * op.x + y * op.y);
  }
  const double operator^(const Point &op) const {
    return (x * op.y - y * op.x);
  }
  const bool operator<(const Point &op) const {
    return (0 < dcmp(op.x - x) || (!dcmp(x - op.x) && 0 < dcmp(op.y - y)));
  }
  const bool operator==(const Point &op) const {
    return (!dcmp(x - op.x) && !dcmp(y - op.y));
  }
  const bool operator!=(const Point &op) const {
    return (dcmp(x - op.x) || dcmp(y - op.y));
  }
};
ostream &operator<<(ostream &out, const Point &p) {
  return out << '(' << p.x << ", " << p.y << ')';
}
struct Line {
  Point s;
  Point t;
  Line(Point _s = Point(), Point _t = Point()) : s(_s), t(_t) {}
  const double ang() const {
    double a = atan2(t.y - s.y, t.x - s.x);
    return a < 0 ? (a + 2 * acos(-1.0)) : a;
  }
  const Point v() const { return t - s; }
};
const double disSqr(const Point &a, const Point &b = Point()) {
  return sqr(a.x - b.x) + sqr(a.y - b.y);
}
const double dis(const Point &a, const Point &b = Point()) {
  return sqrt(disSqr(a, b));
}
const Point rot(const Point &a, const double &ang) {
  return Point(a.x * cos(ang) - a.y * sin(ang),
               a.x * sin(ang) + a.y * cos(ang));
}
const bool pointEqual(const Point &a, const Point &b) {
  return (!dcmp(b.x - a.x) && !dcmp(b.y - a.y));
}
const double cross(const Point &o, const Point &a, const Point &b) {
  return ((a - o) ^ (b - o));
}
double intersectionOfTwoLine(const Point &A, const Point &B, const Point &C,
                             const Point &D) {
  return ((D - C) ^ (A - C)) / ((B - A) ^ (D - C));
}
int intersecPoints(const vector<Point> &gon, const Point &a, const Point &b,
                   vector<pair<double, int> > &intPoints) {
  double intk;
  Point c, d;
  int dirABxAC, dirABxAD;
  intPoints.clear();
  for (int i = 1; i < gon.size(); ++i) {
    c = gon[i - 1];
    d = gon[i];
    dirABxAC = dcmp(cross(a, b, c));
    dirABxAD = dcmp(cross(a, b, d));
    if (dirABxAC == dirABxAD) {
      continue;
    }
    intk = intersectionOfTwoLine(a, b, c, d);
    if (dirABxAC > dirABxAD) {
      intPoints.push_back(make_pair(intk, dirABxAC && dirABxAD ? 2 : 1));
    } else {
      intPoints.push_back(make_pair(intk, dirABxAC && dirABxAD ? -2 : -1));
    }
  }
  return intPoints.size();
}
double commonLine(const vector<Point> &gon, const Point &a, const Point &b) {
  vector<pair<double, int> > intps;
  double cmLineLen = 0;
  int cnt;
  intersecPoints(gon, a, b, intps);
  sort((intps).begin(), (intps).end());
  cnt = 0;
  for (int i = 0; i + 1 < intps.size(); ++i) {
    assert(i + 1 < intps.size());
    cnt += intps[i].second;
    if (cnt) {
      cmLineLen += intps[i + 1].first - intps[i].first;
    }
  }
  return cmLineLen * dis(a, b);
}
int n, m;
vector<Point> gon;
int main(int argc, char *argv[]) {
  double x, y, u, v;
  cout << fixed << setprecision(16);
  R(n, m);
  gon.clear();
  for (int _258 = 1; _258 <= int(n); _258++) {
    R(x, y);
    gon.push_back(Point(x, y));
  }
  gon.push_back(gon[0]);
  for (int _264 = 1; _264 <= int(m); _264++) {
    R(x, y, u, v);
    W(commonLine(gon, Point(x, y), Point(u, v)));
  }
  return 0;
}