#include <bits/stdc++.h>
using namespace std;
#define int long long
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pp pop_back
#define endl '\n'
#define ff first
#define ss second
#define stop exit(0)
#define sz(x) (int)x.size()
#define pause system("pause")
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << "-" << x << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef string str;
typedef long long ll;
typedef long double ld;
typedef __int128_t int128;
typedef vector<int> vii;
typedef pair<int, int> pii;
typedef tuple<int,int,int> tpii;
const long long INF = LLONG_MAX;
const int inf = 100000000;
const int mod = 998244353;
const int MOD = 1000000007;
const int mod67 = 676767677;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const long double PI = 2 * acos(0.0);
const int N = 2e5+5;
inline void test_case() {
int n;
cin >> n;
struct Segment {
ll x1, y1, x2, y2;
ld gety(ld x) const {
if (x1 == x2) return (ld)y1;
return (ld)y1 + (ld)(y2 - y1) * (x - x1) / (ld)(x2 - x1);
}
} seg[n+5];
seg[n] = {-inf,-inf,inf,-inf};
vector <tuple<int,int,int,int>> events;
for (int i = 0; i < n; i++) {
cin >> seg[i].x1 >> seg[i].y1 >> seg[i].x2 >> seg[i].y2;
if (seg[i].x1 > seg[i].x2 || (seg[i].x1 == seg[i].x2 && seg[i].y1 > seg[i].y2)) {
swap(seg[i].x1,seg[i].x2);
swap(seg[i].y1,seg[i].y2);
}
events.eb(seg[i].x1,seg[i].y1,0,i);
events.eb(seg[i].x2,seg[i].y2,1,i);
}
sort(all(events));
int curx = 0;
auto cmp = [&](int a, int b) {
if (a == b) return false;
ld ya = seg[a].gety(curx);
ld yb = seg[b].gety(curx);
if (fabsl(ya - yb) > 1e-18) return ya < yb;
return a < b;
};
set <int,decltype(cmp)> active(cmp);
active.insert(n);
vector <pii> last(n+5,{-inf,-inf});
vii haslast(n+5,0);
vector <tuple<int,int,int,int>> ans;
for (auto [x,y,type,id]:events) {
curx = x;
if (type == 0) {
auto it = active.lower_bound(id);
it--;
int below = *it;
if (haslast[below]) {
ans.eb(last[below].ff,last[below].ss,x,y);
}
last[below] = {x,y};
haslast[below] = 1;
last[id] = {x,y};
haslast[id] = 1;
active.insert(id);
} else {
auto it = active.find(id);
it = prev(active.erase(it));
last[*it] = {seg[id].x2, seg[id].y2};
haslast[*it] = 1;
}
}
for (auto [x1,y1,x2,y2]:ans) {
cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) test_case();
return 0;
}