#include <iostream>
#include <string>
#include <cmath>
#define llint long long
#define inf 1e18
#define eps 1e-9

using namespace std;

struct vec3d{
	double x, y, z;
	vec3d(){}
	vec3d(double x, double y, double z){
		this->x = x, this->y = y, this->z = z;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec3d operator+(vec3d ope){
		return vec3d(add(x, ope.x), add(y, ope.y), add(z, ope.z));
	}
	vec3d operator-(vec3d ope){
		return vec3d(add(x, -ope.x), add(y, -ope.y), add(z, -ope.z));
	}
	double dot(vec3d ope){
		return add(add(x*ope.x, y*ope.y), z*ope.z);
	}
	vec3d cross(vec3d ope){
		double retx = add(y*ope.z, -z*ope.y);
		double rety = add(z*ope.x, -x*ope.z);
		double retz = add(x*ope.y, -y*ope.x);
		return vec3d(retx, rety, retz);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec3d p, vec3d q){
	return (p-q).norm();
}
double distSP(vec3d p, vec3d q, vec3d x){
	if((x-p).dot(q-p) <= 0) return distPP(p, x);
	if((x-q).dot(p-q) <= 0) return distPP(q, x);
	return fabs((x-p).cross(q-p).norm()/distPP(p, q));
}

llint n, Q;
vec3d p[55], s, t;
double r[55];
llint l[55];

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y >> p[i].z >> r[i] >> l[i];
	
	for(int i = 1; i <= Q; i++){
		cin >> s.x >> s.y >> s.z >> t.x >> t.y >> t.z;
		llint ans = 0;
		for(int j = 1; j <= n; j++){
			if(distSP(s, t, p[j]) <= r[j]+eps) ans += l[j];
		}
		cout << ans << endl;
	}
	
	return 0;
}
