### constant

MAX_X = 500

### subroutines

def num_rec(frs, nums)
  while ! frs.empty?
    if frs.length == 1
      $id += 1
      nums[frs.first[0]] = $id
      break
    end

    # step 1
    min_x = MAX_X
    min_fs = []

    for i in (0...frs.length)
      if min_x > frs[i][1]
        min_x = frs[i][1]
        min_fs = [i]
      elsif min_x == frs[i][1]
        min_fs << i
      end
    end

    min_f = min_fs.sort!{|a, b| frs[a][2] <=> frs[b][2]}.first
    si, sx0, sy0, sx1, sy1 = frs.delete_at(min_f)

    $id += 1
    nums[si] = $id

    # step 2
    lx0 = sx0
    lx1 = MAX_X
    ly = sy1

    for fr in frs
      i, x0, y0, x1, y1 = fr
      if x0 < lx1 && y0 < ly && y1 > ly
        lx1 = x0
      end
    end

    # step 3
    frs0 = []

    for fr in frs
      i, x0, y0, x1, y1 = fr
      if x1 <= lx1 && y1 <= ly
        frs0 << fr
      end
    end

    frs -= frs0

    num_rec(frs0, nums)
  end
end

### main

prev = false

loop do
  n = gets.to_i
  break if n == 0

  frames = []

  for i in (0...n)
    x0, y0, x1, y1 = gets.split.map(&:to_i)
    if x0 > x1
      x0, x1 = x1, x0
    end
    if y0 > y1
      y0, y1 = y1, y0
    end
    frames << [i, x0, y0, x1, y1]
  end
  #p frames

  rfrs = frames.clone
  $id = 0

  nums = []
  num_rec(rfrs, nums)

  if prev
    puts
  end
  prev = true

  puts nums
end