#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;
}
