#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


//3次元
struct Point{
	Point(double arg_x,double arg_y,double arg_z){
		x = arg_x;
		y = arg_y;
		z = arg_z;
	}

	Point(){
		x = y = z = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y,z+p.z); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y,z-p.z);}
	Point operator * (double a){ return Point(a*x,a*y,a*z); }
	Point operator / (double a){ return Point(x/a,y/a,z/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y + z*z; }

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS && fabs(z-p.z) < EPS;
	}
	double x,y,z;
};

typedef Point Vector;

struct Line{
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	Point p[2];
};

struct Info{
	Point center;
	double r;
	ll value;
};

int N,Q;
Info info[50];

//3次元
double norm(Vector a){
	return a.x*a.x+a.y*a.y+a.z*a.z;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y+a.z*b.z;
}

//垂線が引ける場合、交点を求める
Point projection(Line line,Point point){
    double t = dot(point-line.p[0],line.p[0]-line.p[1])/norm(line.p[0]-line.p[1]);
    return line.p[0] + (line.p[0]-line.p[1])*t;
}

double calc_dist(Point a,Point b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

bool intersect(Line line,int index){

	double dist_1 = calc_dist(line.p[0],info[index].center);
	double dist_2 = calc_dist(line.p[1],info[index].center);

	//方向ベクトル
	double Vx = line.p[1].x-line.p[0].x;
	double Vy = line.p[1].y-line.p[0].y;
	double Vz = line.p[1].z-line.p[0].z;

	//Oを原点,点Aをline.p[0]としたとき、点info[inde]から下した垂線との交点が、(line.p[0].x+t*Vx,line.p[0].y+t*Vy,line.p[0].z+t*Vz)と表されるようなt
	double t = (Vx*(info[index].center.x-line.p[0].x)+Vy*(info[index].center.y-line.p[0].y)+Vz*(info[index].center.z-line.p[0].z))/(Vx*Vx+Vy*Vy+Vz*Vz);

	if(t < 0 || t > 1){ //垂線が、観測点と光源を結ぶ線分上にない場合→最近地点は、観測点か光源のどちらか
		if(dist_1 > info[index].r && dist_2 > info[index].r){
			return false;
		}else{
			return true;
		}
	}

	double cross_x = line.p[0].x+t*Vx;
	double cross_y = line.p[0].y+t*Vy;
	double cross_z = line.p[0].z+t*Vz;

	double dist = sqrt((info[index].center.x-cross_x)*(info[index].center.x-cross_x)
			+(info[index].center.y-cross_y)*(info[index].center.y-cross_y)
			+(info[index].center.z-cross_z)*(info[index].center.z-cross_z)
		);

	if(dist < info[index].r+EPS){
		return true;
	}else{
		return false;
	}
}

int main(){

	scanf("%d %d",&N,&Q);

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf %lf %lld",&info[i].center.x,&info[i].center.y,&info[i].center.z,&info[i].r,&info[i].value);
	}

	Point a,b;
	ll ans;
	for(int loop = 0; loop < Q; loop++){
		scanf("%lf %lf %lf %lf %lf %lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z);
		ans = 0;
		Line line(a,b);
		for(int i = 0; i < N; i++){
			if(intersect(line,i))ans += info[i].value;
		}

		printf("%lld\n",ans);
	}

	return 0;
}




Measured memory_bytes: 3240