#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
double dist(double a,double b,double c){
	return sqrt(a*a+b*b+c*c);
}
int main(){
	int n,m;
	cin>>n>>m;
	vvd boll(n,vd(4));
	vi sc(n);
	rep(i,n){
		rep(j,4)cin>>boll[i][j];
		cin>>sc[i];
	}
	while(m--){
		ll out=0;
		double a,b,c,d,e,f;
		cin>>a>>b>>c>>d>>e>>f;
		rep(i,n){
			vd q{boll[i][0],boll[i][1],boll[i][2]};
			double A=d-a,B=e-b,C=f-c;
			double ssita=sqrt(pow(B*(q[2]-c)-C*(q[1]-b),2)+pow(C*(q[0]-a)-A*(q[2]-c),2)+pow(A*(q[1]-b)-B*(q[0]-a),2))/
				dist(A,B,C)/dist(q[0]-a,q[1]-b,q[2]-c);
			double dis=dist(q[0]-a,q[1]-b,q[2]-c)*ssita;
			if(dis<boll[i][3]+EPS){
				double dot1=A*(q[0]-a)+B*(q[1]-b)+C*(q[2]-c);
				double dot2=A*(q[0]-d)+B*(q[1]-e)+C*(q[2]-f);
//				cout<<i<<" "<<dot1<<" "<<dot2<<endl;
				if(dot1>=0&&dot2<=0)out+=sc[i];
			}
		}
		cout<<out<<endl;
	}
}