//
// Noszály Áron 9a Debreceni Fazekas Mihály Gimnázium
// noszalyaron4@gmail.com
//
// g++ 5.4.0 -std=c++14
//
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
#define all(s) (s).begin(),(s).end()
#define pb push_back
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define INF std::numeric_limits<int>::max()
#define MINF std::numeric_limits<int>::min()
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) ((void)0)
#endif
const long double PI = acos(-1);
int d1[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int d2[8][2]={{1,0},{0,1},{0,-1},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};
#define LENGYEL
struct PP {
int x,y,i;
PP(int x_, int y_, int i_) {
x=x_;
y=y_;
i=i_;
}
bool operator<(const PP& b) const {
if(y==b.y) return x<b.x;
return y<b.y;
}
};
int ansx[10001],ansy[10001];
int main()
{
IO;
int n;cin>>n;
vector<PP> X,Y;
for(int i=0;i<n;++i) {
ansx[i]=ansy[i]=-1;
int a,b,c,d;cin>>a>>b>>c>>d;
X.pb(PP(a,c,i));
Y.pb(PP(b,d,i));
}
sort(all(X));
sort(all(Y));
set<int> XX, YY;
for(int i=1;i<=n;++i) {
XX.insert(i);YY.insert(i);
}
for(int i=0;i<n;++i) {
set<int>::iterator it=XX.lower_bound(X[i].x);
if(it==XX.end() || (*it)>X[i].y) {
#ifdef LENGYEL
cout<<"NIE\n";
#else
cout<<"-1\n";
#endif
return 0;
}
ansx[X[i].i]=*it;
XX.erase(it);
}
for(int i=0;i<n;++i) {
set<int>::iterator it=YY.lower_bound(Y[i].x);
if(it==Y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K2kpIHsKCQlYWC5pbnNlcnQoaSk7WVkuaW5zZXJ0KGkpOwoJfQoKCiAgICBmb3IoaW50IGk9MDtpPG47KytpKSB7CgogICAgICAgIHNldDxpbnQ+OjppdGVyYXRvciBpdD1YWC5sb3dlcl9ib3VuZChYW2ldLngpOwogICAgICAgIGlmKGl0PT1YWC5lbmQoKSB8fCAoKml0KT5YW2ldLnkpIHsKICAgICAgICAgICAgI2lmZGVmIExFTkdZRUwKCQkJCWNvdXQ8PCJOSUVcbiI7CiAgICAgICAgICAgICNlbHNlCgkJCQljb3V0PDwiLTFcbiI7CiAgICAgICAgICAgICNlbmRpZgogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CgogICAgICAgIGFuc3hbWFtpXS5pXT0qaXQ7CiAgICAgICAgWFguZXJhc2UoaXQpOwogICAgfQoKICAgIGZvcihpbnQgaT0wO2k8bjsrK2kpIHsKICAgICAgICBzZXQ8aW50Pjo6aXRlcmF0b3IgaXQ9WVkubG93ZXJfYm91bmQoWVtpXS54KTsKICAgICAgICBpZihpdD09WVkuZW5kKCkgfHwgKCppdCk+WVtpXS55KSB7CiAgICAgICAgICAgICNpZmRlZiBMRU5HWUVMCgkJCQljb3V0PDwiTklFXG4iOwogICAgICAgICAgICAjZWxzZQoJCQkJY291dDw8Ii0xXG4iOwogICAgICAgICAgICAjZW5kaWYKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQoKICAgICAgICBhbnN5W1lbaV0uaV09Kml0OwogICAgICAgIFlZLmVyYXNlKGl0KTsKICAgIH0KCiAgICBmb3IoaW50IGk9MDtpPG47KytpKSB7CiAgICAgICAgY291dDw8YW5zeFtpXTw8IiAiPDxhbnN5W2ldPDwiXG4iOwogICAgfQoKCglyZXR1cm4gMDsKfQo=