def overlap(d1,d2)
    Math.sqrt((d2[0] - d1[0])**2 + (d2[1] - d1[1])**2) < d1[2] + d2[2]
end
def dfs(ds, on)
    if (top = ds.size.times.select{|i| on[i].size == 0}).size > 0
        max = 0
        top.combination(2) do |a,b|
            next if ds[a][3] != ds[b][3]
            onn = Marshal.load(Marshal.dump(on))
            onn[a].push(-1)
            onn[b].push(-1)
            onn.size.times do |i|
                onn[i].delete(a)
                onn[i].delete(b)
            end
            res = 2 + dfs(ds,onn)
            max = res if res > max
        end
    end
    return max
end
loop do
    n = gets.to_i
    break if n == 0
    ds = n.times.map{gets.split.map(&:to_i)}
    on = Array.new(n).map{Array.new}
    ds.each_with_index do |d1, i|
        (i+1).upto(n-1) do |j|
            d2 = ds[j]
            if overlap(d1,d2)
                on[j].push(i)
            end
        end
    end
    p dfs(ds,on)
end