#include template std::ostream &operator<<(std::ostream &os, const std::pair &p) { os << "[" << p.first << " " << p.second << "]"; return os; } int main() { using namespace std; unsigned N, M; cin >> N >> M; using point = pair; vector> segments(N); for (auto &&[p1, p2] : segments) { auto &&[x1, y1]{p1}; auto &&[x2, y2]{p2}; long a, b, c, d; cin >> a >> b >> c >> d; x1 = a + 10000; y1 = b + 10000; x2 = c + 10000; y2 = d + 10000; } vector distances(2 * N, vector(2 * N, sqrt(numeric_limits::max()))); const auto side{[](const auto &p, const auto &segment) { const auto &[x, y]{p}; const auto &[p1, p2]{segment}; const auto &[x1, y1]{p1}; const auto &[x2, y2]{p2}; const auto positive_part{x1 * y2 + x2 * y + x * y1}; const auto negative_part{x2 * y1 + x * y2 + x1 * y}; return (positive_part > negative_part) - (positive_part < negative_part); }}; for (unsigned i{}; i < 2 * N; ++i) { const auto &p1{i & 1 ? segments[i / 2].second : segments[i / 2].first}; for (unsigned j{}; j < 2 * N; ++j) { const auto &p2{j & 1 ? segments[j / 2].second : segments[j / 2].first}; if (ranges::all_of(segments, [&side, &p1, &p2](const auto &s) { auto x{side(p1, s)}, y{side(p2, s)}; auto t{side(s.first, make_pair(p1, p2))}, u{side(s.second, make_pair(p1, p2))}; if (x * y + 1 == 0 && t * u + 1 == 0) return false; return true; })) distances[i][j] = hypot(static_cast(p1.first) - p2.first, static_cast(p1.second) - p2.second); } } for (unsigned _{}; _ < 3; ++_) for (unsigned k{}; k < 2 * N; ++k) for (unsigned i{}; i < 2 * N; ++i) for (unsigned j{}; j < 2 * N; ++j) distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]); cout << fixed << setprecision(15); for (unsigned i{}, a, b, c, d; i < M; ++i) { cin >> a >> b >> c >> d; --a; --b; --c; --d; cout << distances[a * 2 + b][c * 2 + d] << endl; } return 0; }