### constant

DELTA = 1e-6

EV_ST = 0
EV_FN = 1
EV_IS = 2
EV_IF = 3

### subroutines

def root(uft, i)
  ri = i
  while uft[ri] != ri
    ri = uft[ri]
  end
  uft[i] = ri
end

### main

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

  $sphs = $n.times.map{gets.split.map(&:to_f)}
  #p $sphs

  events = []
  zs = []
  zranges = []

  for i in (0...$n)
    xi, yi, zi, ri = $sphs[i]

    zi0 = zi - ri
    zi1 = zi + ri
    events << [zi0, EV_ST]
    events << [zi1, EV_FN]
    zs += [zi0, zi1]
    zranges << [zi0, zi1]

    for j in ((i + 1)...$n)
      xj, yj, zj, rj = $sphs[j]

      dx = xj - xi
      dy = yj - yi
      dz = zj - zi
      dc2 = dx * dx + dy * dy + dz * dz

      if (rj - ri) ** 2 < dc2 && dc2 < (rj + ri) ** 2
        dc = Math.sqrt(dc2)
        a = (rj * rj - ri * ri + dc2) / (2 * dc)
        if ri < a
          a = (rj * rj - ri * ri - dc2) / (2 * dc)
        end
        #p ['ri', ri, 'a', a]
        b = Math.sqrt(ri * ri - a * a)
        th = Math.atan2(dz, Math.sqrt(dx * dx + dy * dy))
        zc = zi + a * Math.sin(th)
        dzc = b * Math.cos(th)

        events << [zc - dzc, EV_IS]
        events << [zc + dzc, EV_IF]
        zs += [zc - dzc, zc + dzc]
      end
    end
  end

  events.sort!
  zs.sort!
  #p events
  #p zs

  nc = 0
  bits = []
  
  events.each do |z, ev|
    uft = $n.times.map{nil}
    rzs = []
    
    for i in (0...$n)
      zi0, zi1 = zranges[i]
      next if z < zi0 || zi1 <= z

      uft[i] = i
      xi, yi, zi, ri = $sphs[i]
      rzs[i] = Math.sqrt(ri * ri - (z - zi) ** 2)
    end

    for i in (0...$n)
      next if uft[i].nil?
      xi, yi, zi, ri = $sphs[i]
      rzi = rzs[i]
      ui = root(uft, i)
      
      for j in ((i + 1)...$n)
        next if uft[j].nil?

        uj = root(uft, j)
        next if ui == uj
        
        xj, yj, zj, rj = $sphs[j]
        rzj = rzs[j]

        delta = (ev == EV_ST || ev == EV_IS) ? DELTA : -DELTA
        
        #p [i, j, (xj - xi) ** 2 + (yj - yi) ** 2, (rzj + rzi) ** 2]
        if (xj - xi) ** 2 + (yj - yi) ** 2 <= (rzj + rzi) ** 2 + delta
          uft[j] = ui
        end
      end
    end

    chash = {}
    uft.compact.each{|i| chash[root(uft, i)] = true}
    count = chash.keys.length

    if nc < count
      bits << 1
    elsif nc > count
      bits << 0
    end

    nc = count

    #p uft
    #p count
  end

  puts bits.length
  puts bits.join('')
end