### constant

MAX_C = 4

### subroutines

def overwrap?(dsk0, dsk1)
  x0, y0, r0 = dsk0
  x1, y1, r1 = dsk1
  (x1 - x0) ** 2 + (y1 - y0) ** 2 < (r0 + r1) ** 2
end

def count_rec(n, clrs, ovs, used)
  max_cnt = 0

  for ids in clrs
    len = ids.length
    for cid0 in (0...len)
      id0 = ids[cid0]
      next if used[id0] || ! ovs[id0].select{|id| ! used[id]}.empty?

      for cid1 in ((cid0 + 1)...len)
        id1 = ids[cid1]
        next if used[id1] || ! ovs[id1].select{|id| ! used[id]}.empty?

        used[id0] = used[id1] = true
        cnt = 2 + count_rec(n, clrs, ovs, used)
        used[id0] = used[id1] = false

        max_cnt = cnt if max_cnt < cnt
      end
    end
  end    
  
  max_cnt
end

### main

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

  dsks = []
  clrs = MAX_C.times.map{[]}
  
  for i in (0...n)
    xi, yi, ri, ci = gets.split.map(&:to_i)
    ci -= 1
    dsk = [xi, yi, ri, ci]
    dsks << dsk
    clrs[ci] << i
  end
  #p dsks
  #p clrs

  ovs = n.times.map{[]}
  
  for i in (0...n)
    dski = dsks[i]
    for j in ((i + 1)...n)
      dskj = dsks[j]
      if overwrap?(dski, dskj)
        ovs[j] << i
      end
    end
  end
  #p ovs

  cnt = count_rec(n, clrs, ovs, n.times.map{false})
  puts cnt
end