// AOJ 1064: Yanagi's Comic
// 2018.1.17 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef struct { int id, th, x1, y1, x2, y2; char used; } T;
T tbl[10]; int n;
int ans;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void calc(int k)
{
	int i, y, x1, x2, xx, yy, j;

	if (k == n) return;
	tbl[k].th = ++ans, tbl[k].used = 1;
	y = tbl[k].y2, x1 = tbl[k].x1, x2 = 501;
	for (i = 0; i < n; i++) {
		if (tbl[i].used) continue;
		if (tbl[i].y1 < y && y < tbl[i].y2) { x2 = tbl[i].x1; break; }
	}
	xx = yy = 501, j = -1;
	for (i = 0; i < n; i++) {
		if (tbl[i].used) continue;
		if (tbl[i].y2 <= y && tbl[i].x1 >= x1 && tbl[i].x2 <= x2) {
			if (tbl[i].x1 < xx || (tbl[i].x1 == xx && tbl[i].y1 < yy))
				xx = tbl[i].x1, yy = tbl[i].y1, j = i;
		}
	}
	if (j >= 0) calc(j);
}

int cmpxy(T *a, T *b) { if (a->x1 - b->x1) return a->x1 - b->x1; return a->y1 - b->y1; }
int cmpid(T *a, T *b) { return a->id - b->id; }

int main()
{
	int x1, y1, x2, y2;
	int cno, i;

	cno = 0; while (n = in()) {
		for (i = 0; i < n; i++) {
			x1 = in(), y1 = in(), x2 = in(), y2 = in();
			tbl[i].id = i, tbl[i].used = 0;
			if (x1 <= x2) tbl[i].x1 = x1, tbl[i].x2 = x2;
			else          tbl[i].x1 = x2, tbl[i].x2 = x1;
			if (y1 <= y2) tbl[i].y1 = y1, tbl[i].y2 = y2;
			else          tbl[i].y1 = y2, tbl[i].y2 = y1;
		}
		qsort(tbl, n, sizeof(T), cmpxy);

		ans = 0;
		for (i = 0; i < n; i++) if (tbl[i].used == 0) calc(i);

		qsort(tbl, n, sizeof(T), cmpid);
		if (!cno) cno = 1;
		else putchar('\n');
		for (i = 0; i < n; i++) printf("%d\n", tbl[i].th);
	}
	return 0;
}
