require 'set'
require 'matrix'

def d2(x1, y1, z1, x2, y2, z2)
	(x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2
end

loop do
	n, m, removable = gets.split.map(&:to_i)
	break if n == 0
	baloons = (1..n).map {gets.split.map(&:to_i)}
	lights = (1..m).map {gets.split.map(&:to_i)}
	x0, y0, z0 = gets.split.map(&:to_i)
	intensity = lights.map do |x, y, z, b|
		b.to_f / d2(x, y, z, x0, y0, z0)
	end
	cost = lights.map do |xl, yl, zl, _|
		u = Vector[xl - x0, yl - y0, zl - z0]
		set = Set.new
		(0..n-1).each do |i|
			xb, yb, zb, r = baloons[i]
			v = Vector[xb - x0, yb - y0, zb - z0]
			w = v - u
			if (v.r < r) ^ (w.r < r)
				set << i
			else
				a = v.inner_product(u) / u.r
				if 0 < a && a < u.r && (v.r >= r) && (w.r >= r) && v.r ** 2 - a ** 2 < r * 2
					set << i
				end
			end
		end
		set
	end

	max = 0
	(1..2**m-1).each do |x|
		c = Set.new
		v = 0
		(0..n-1).each do |i|
			if x[i] == 1
				c += cost[i]
				v += intensity[i]
			end
		end
		next if c.size > removable
		max = v if v > max
	end
	p max
end