#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	bool read;
	int x0,y0,x1,y1;
};


int N,test_case = 0;
Info info[10];
int table[10];

void func(){

	if(test_case != 0){
		printf("\n");
	}
	test_case++;

	for(int i = 0; i < N; i++){
		scanf("%d %d %d %d",&info[i].x0,&info[i].y0,&info[i].x1,&info[i].y1);
		if(info[i].x1 < info[i].x0)swap(info[i].x1,info[i].x0);
		if(info[i].y1 < info[i].y0)swap(info[i].y1,info[i].y0);
		info[i].read = false;
	}

	stack<vector<int>> S;

	int read_num = 0;
	int order = 1,left;

	int min_x,min_y,min_index;
	vector<int> TMP,NEXT,NEXT_NEXT;
	bool check[N];

	while(true){

		min_x = BIG_NUM;
		min_y = BIG_NUM;
		TMP.clear();

		if(S.size() == 0){

			for(int i = 0; i < N; i++){
				if(info[i].read)continue;

				if(info[i].x0 < min_x){
					min_x = info[i].x0;
					min_y = info[i].y0;
					min_index = i;
				}else if(info[i].x0 == min_x && info[i].y0 < min_y){
					min_y = info[i].y0;
					min_index = i;
				}
			}

			table[min_index] = order++;
			info[min_index].read = true;
			read_num++;
			if(read_num == N)break;

			TMP.clear();

			left = BIG_NUM;
			for(int i = 0; i < N; i++){
				if(info[i].x0 >= info[min_index].x1 && info[i].y0 < info[min_index].y1 && info[i].y1 > info[min_index].y1){
					left = min(left,info[i].x0);
				}
			}

			for(int i = 0; i < N; i++){
				if(info[i].read)continue;

				if(info[i].y1 <= info[min_index].y1 && info[i].x0 >= info[min_index].x0 && info[i].x1 <= left){
					TMP.push_back(i);
				}
			}
			if(TMP.size() > 0){
				S.push(TMP);
			}

		}else{
			TMP = S.top();
			S.pop();
			NEXT.clear();
			NEXT_NEXT.clear();

			for(int i = 0; i < N; i++)check[i] = false;

			for(int i = 0; i < TMP.size(); i++){
				if(info[TMP[i]].read)continue;

				if(info[TMP[i]].x0 < min_x){
					min_x = info[TMP[i]].x0;
					min_y = info[TMP[i]].y0;
					min_index = TMP[i];
				}else if(info[TMP[i]].x0 == min_x && info[TMP[i]].y0 < min_y){
					min_y = info[TMP[i]].y0;
					min_index = TMP[i];
				}
			}

			table[min_index] = order++;
			info[min_index].read = true;
			read_num++;
			if(read_num == N)break;

			left = BIG_NUM;
			for(int i = 0; i < N; i++){
				if(info[i].x0 >= info[min_index].x1 && info[i].y0 < info[min_index].y1 && info[i].y1 > info[min_index].y1){
					left = min(left,info[i].x0);
				}
			}

			for(int i = 0; i < N; i++){
				if(info[i].read)continue;

				if(info[i].y1 <= info[min_index].y1 && info[i].x0 >= info[min_index].x0 && info[i].x1 <= left){
					NEXT.push_back(i);
					check[i] = true;
				}
			}
			for(int i = 0; i < TMP.size(); i++){
				if(TMP[i] == min_index)continue;

				if(check[TMP[i]] == false){
					NEXT_NEXT.push_back(TMP[i]);
				}
			}

			if(NEXT_NEXT.size() > 0)S.push(NEXT_NEXT);
			if(NEXT.size() > 0)S.push(NEXT);
		}
	}

	for(int i = 0; i < N; i++){
		printf("%d\n",table[i]);
	}

}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3280