#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

class State {
public:
  int x1,x2,y1,y2,num;
  State(){}

  bool operator < (const State s) const {
    if(x1 == s.x1) return y1 < s.y1;
    return x1 < s.x1;
  }

};

State t[10],t2[10];
int n;
int used[10];
int cnt;
map<int, int> mp; // num -> index


void solve(vector<int> v){

  for(int i=0; i<v.size(); i++){
    int index = v[i];
    if(used[index] != -1) continue;
    used[index] = cnt++;
    index = mp[index];
    //    cout << "index = " << mp[index] << endl;


    int X1 = t[index].x1, X2 = 50000, Y1 = t[index].y1, Y2 = t[index].y2;
    //    cout << "X1 = " << X1 << " X2 = " << X2 << " Y1 = " << Y1 << " Y2 = " << Y2 << endl;

    for(int j=0; j<n; j++){
      //      if(used[t[j].num] != -1)continue;
      if(t[j].y2 > Y2 && t[j].y1 < Y2 && t[j].x1 >= t[index].x1){
	  X2 = min(X2,t[j].x1);
	  break;
	}
    }



    vector<int>tmp;
    for(int j=0; j<n; j++){
      if(used[t[j].num] != -1)continue;
      if(t[j].y2 <= Y2 && X2 >= t[j].x2 && t[j].x1 >= X1){
	tmp.push_back(t[j].num);
	//	cout << "num = " << t[j].num + 1 << endl;
      }
    }
    solve(tmp);
  }
}

int main(){
  bool f = false;
  while(cin >> n && n){

    if(f) cout << endl;
    f = true;

    cnt = 1;
    fill(used,used+10,-1);

    for(int i=0; i<n; i++){
      cin >> t[i].x1 >> t[i].y1 >> t[i].x2 >> t[i].y2;
      if(t[i].x1 > t[i].x2) swap(t[i].x1,t[i].x2);
      if(t[i].y1 > t[i].y2) swap(t[i].y1,t[i].y2);
      t[i].num = i;
    }

    for(int i=0; i<n; i++) t2[i] = t[i];

    sort(t,t+n);
    
    for(int i = 0 ; i < n ; i++){
      mp[t[i].num] = i;
    }
    
    for(int i=0; i<n; i++){
      //      cout << "x1 = " << t[i].x1 << " y1 = " << t[i].y1 << " x2 = " << t[i].x2 << " y2 = " << t[i].y2 << 
      //	" num = " << t[i].num << endl;
    }


    vector<int>v;
    for(int i=0; i<n; i++) v.push_back(t[i].num);
    solve(v);

    for(int i=0; i<n; i++) cout << used[i] << endl;

  }
  return 0;
}