#include<bits/stdc++.h>
using namespace std;

const double eps = 0.0000000001;

bool eq(double a,double b){
  return ( fabs(a-b) < eps );
}

struct Point{
  double x,y,z;
  
  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 k){
    return (Point){x*k,y*k,z*k};
  }
};
typedef Point Vector;

struct Segment{
  Point p, v;
};
typedef Segment Line;

bool isIntersect(Segment a,Point b,double r){
  double X=a.p.x-b.x;
  double Y=a.p.y-b.y;
  double Z=a.p.z-b.z;
  double A=(a.v.x*a.v.x+a.v.y*a.v.y+a.v.z*a.v.z);
  double B=(X*a.v.x+Y*a.v.y+Z*a.v.z)*2.0;
  double C=X*X+Y*Y+Z*Z-r*r;
  double K=B*B-4.0*A*C;
  if( K < -eps )return false;
  if( eq(K,0) )K=0;
  double t =  (-B + sqrt(B*B-4.0*A*C)) / (2.0*A);
  double t2 =  (-B - sqrt(B*B-4.0*A*C)) / (2.0*A);
  if( 0 < t && t < 1)return true;
  if( 0 < t2 && t2 < 1)return true;
  return false;
}

int N,Q;
Point A[50];
double B[50];
long long C[50];

int main(){
  cin>>N>>Q;
  for(int i=0;i<N;i++){
    cin>>A[i].x>>A[i].y>>A[i].z;
    cin>>B[i]>>C[i];
  }
  for(int i=0;i<Q;i++){
    long long ans=0;
    Segment s;
    cin>>s.p.x>>s.p.y>>s.p.z;
    cin>>s.v.x>>s.v.y>>s.v.z;
    s.v = s.v - s.p;
    for(int j=0;j<N;j++)
      if(isIntersect(s,A[j],B[j]))ans+=C[j];
    cout<<ans<<endl;
  }
  return 0;
}