#include <bits/stdc++.h>
using namespace std;
struct point {
  long long int x, y;
  point() {}
  point(long long int inx, long long int iny) {
    x = inx;
    y = iny;
  }
};
point operator-(point p1, point p2) {
  p1.x -= p2.x;
  p1.y -= p2.y;
  return p1;
}
long long int prodvec(point p1, point p2) { return p1.x * p2.y - p1.y * p2.x; }
long long int prodesc(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; }
point rotar(point a, point p) { return point(prodesc(a, p), prodvec(a, p)); }
long double abs(point p) {
  long double x = p.x;
  long double y = p.y;
  return sqrt(x * x + y * y);
}
long long int leer() {
  long double x;
  cin >> x;
  return round(x * 100);
}
point leerpunto() {
  long long int x = leer();
  long long int y = leer();
  return point(x, y);
}
int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  int n, casos;
  cin >> n >> casos;
  vector<point> v(n);
  for (int i = 0; i < n; i++) v[i] = leerpunto();
  for (int caso = 0; caso < casos; caso++) {
    point p = leerpunto();
    point q = leerpunto();
    point d = q - p;
    long double modulod = abs(d);
    vector<point> w(n);
    vector<long double> xx(n), yy(n);
    for (int i = 0; i < n; i++) {
      w[i] = rotar(d, v[i] - p);
      if (w[i].x != 0 or w[i].y != 0) {
        xx[i] = w[i].x;
        yy[i] = w[i].y;
      } else {
        xx[i] = yy[i] = 0;
      }
    }
    vector<pair<long double, int> > lista;
    for (int i = 0; i < n; i++) {
      int nexti = (i + 1) % n;
      int anti = (i - 1 + n) % n;
      point p = w[i];
      point antp = w[anti];
      point nextp = w[nexti];
      if ((p.y < 0 and 0 < nextp.y) or (nextp.y < 0 and 0 < p.y)) {
        long double x = xx[i];
        long double y = yy[i];
        long double nextx = xx[nexti];
        long double nexty = yy[nexti];
        lista.push_back(pair<long double, int>(
            x + (nextx - x) * abs(y) / abs(y - nexty), 0));
      } else if (p.y == 0) {
        long double x = xx[i];
        if (antp.y < 0) {
          if (nextp.y > 0) {
            lista.push_back(pair<long double, int>(x, 0));
          } else if (nextp.y == 0) {
            lista.push_back(pair<long double, int>(x, -1));
          }
        } else if (antp.y > 0) {
          if (nextp.y < 0) {
            lista.push_back(pair<long double, int>(x, 0));
          } else if (nextp.y == 0) {
            lista.push_back(pair<long double, int>(x, 1));
          }
        } else if (nextp.y < 0) {
          lista.push_back(pair<long double, int>(x, -1));
        } else if (nextp.y > 0) {
          lista.push_back(pair<long double, int>(x, 1));
        }
      }
    }
    sort(lista.begin(), lista.end());
    bool dentro = false;
    long double antx;
    long double sol = 0;
    for (int i = 0; i < int(lista.size()); i++) {
      long double x = lista[i].first;
      int s = lista[i].second;
      if (dentro) sol += x - antx;
      if (s == 0) {
        dentro = not dentro;
      } else {
        sol += lista[i + 1].first - x;
        dentro = dentro xor (lista[i + 1].second != s);
        i++;
      }
      antx = lista[i].first;
    }
    cout << sol / (100.0 * modulod) << endl;
  }
}
