1. Abridged Problem Statement
Given K axis-aligned segments that form a simple closed polygon (no self-intersections), determine for a query point (X₀, Y₀) whether it lies strictly inside the polygon, strictly outside it, or exactly on one of its segments (border).

2. Detailed Editorial

Overview
We want a classic “point-in-polygon” test specialized to axis-aligned edges. We’ll also detect if the point lies on any segment.

Approach
Use a ray-casting (crossing number) method with a vertical ray shooting downward from the point. Count how many edges the ray crosses; odd → inside, even → outside. The border check is performed in the same pass.

Steps
1) Read all K segments and the query point (X₀, Y₀).
2) Border check (per segment):
   - For each vertical segment (x₁=x₂): if X₀ = x₁ and Y₀ between y₁ and y₂ (inclusive), output BORDER.
   - For each horizontal segment (y₁=y₂): if Y₀ = y₁ and X₀ between x₁ and x₂ (inclusive), output BORDER.
3) Crossing count: cast a ray from (X₀, Y₀) straight down (decreasing Y).
   - Only horizontal segments can be intersected by a vertical ray.
   - For each horizontal segment at y = Y₁ with Y₁ < Y₀ (below the point): count one intersection when X₀ lies in the half-open span (min(x₁,x₂), max(x₁,x₂)].
     * Using “min(x₁,x₂) < X₀ ≤ max(x₁,x₂)” handles vertex cases correctly and avoids double-counting shared endpoints.
4) If the total intersection count is odd → INSIDE; else → OUTSIDE.

Time Complexity
O(K), scanning each segment a constant number of times. Memory O(K).

3. C++ Solution
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<pair<pair<int, int>, pair<int, int>>> segments;
pair<int, int> tgt;

void read() {
    cin >> n;
    segments.resize(n);
    cin >> segments;
    cin >> tgt;
}

void solve() {
    /*
     * Point-in-polygon test for an axis-parallel rectilinear closed loop via
     * a horizontal ray cast downward from the query point.
     *
     * For each segment: if the point lies on a vertical or horizontal segment
     * it is on the BORDER. Otherwise, count horizontal segments strictly below
     * the point whose x-span covers the point's x (half-open in x so shared
     * endpoints are counted once); odd count means INSIDE, even means OUTSIDE.
     */

    int cnt = 0;
    for(int i = 0; i < (int)segments.size(); i++) {
        auto [p1, p2] = segments[i];
        auto [x1, y1] = p1;
        auto [x2, y2] = p2;

        if(x1 == x2 && tgt.second >= min(y1, y2) && tgt.second <= max(y1, y2) &&
           tgt.first == x1) {
            cout << "BORDER" << endl;
            return;
        }

        if(y1 == y2 && tgt.second == y1 && min(x1, x2) <= tgt.first &&
           tgt.first <= max(x1, x2)) {
            cout << "BORDER" << endl;
            return;
        }

        if(y1 == y2 && tgt.second < y1 && min(x1, x2) < tgt.first &&
           tgt.first <= max(x1, x2)) {
            cnt++;
        }
    }

    if(cnt % 2 == 0) {
        cout << "OUTSIDE" << endl;
    } else {
        cout << "INSIDE" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution with Detailed Comments
```python
import sys

def main():
    data = sys.stdin.read().strip().split()
    it = iter(data)

    # Read number of segments
    K = int(next(it))
    segments = []
    for _ in range(K):
        x1 = int(next(it)); y1 = int(next(it))
        x2 = int(next(it)); y2 = int(next(it))
        segments.append((x1, y1, x2, y2))

    # Read query point
    X0 = int(next(it)); Y0 = int(next(it))

    crossings = 0
    for x1, y1, x2, y2 in segments:
        # Border check on vertical segments
        if x1 == x2:
            if X0 == x1 and min(y1, y2) <= Y0 <= max(y1, y2):
                print("BORDER")
                return
        else:
            # Border check on horizontal segments
            if Y0 == y1 and min(x1, x2) <= X0 <= max(x1, x2):
                print("BORDER")
                return
            # Downward ray: count horizontal segments strictly below the point
            if y1 < Y0:
                xl, xr = sorted((x1, x2))
                # Use (xl, xr] to avoid double count at shared vertices
                if xl < X0 <= xr:
                    crossings += 1

    # Odd -> INSIDE; Even -> OUTSIDE
    print("INSIDE" if crossings % 2 else "OUTSIDE")

if __name__ == "__main__":
    main()
```

5. Compressed Editorial
Shoot a vertical ray downward from the point. While scanning segments, if the point lies exactly on any segment → BORDER. Otherwise, for each horizontal edge below the point whose x-span contains the point (using `(min_x < X0 ≤ max_x)` to handle vertices), increment a crossing counter. If the count is odd → INSIDE, else → OUTSIDE. This runs in O(K).
