#include <iostream>
#include <cstdio>
#include <cmath>
#define eps 0.0000001
using namespace std;
struct po{int x,y,z,r; long long l;};
struct popo{int x,y,z;};

double mk_dis(popo a,popo 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));
}

int main(){
  int n,q;
  cin >>n>>q;
  po ball[51];
  for(int i=0;i<n;i++)cin>>ball[i].x>>ball[i].y>>ball[i].z>>ball[i].r>>ball[i].l;
  
  for(int i=0;i<q;i++){
    int a1,a2,b1,b2,c1,c2;
    double dis[3];
    cin >>a1>>b1>>c1>>a2>>b2>>c2;
    dis[0] = mk_dis((popo){a1,b1,c1},(popo){a2,b2,c2});
    long long ans=0;
    for(int j=0;j<n;j++){
      dis[1] = mk_dis((popo){a1,b1,c1},(popo){ball[j].x,ball[j].y,ball[j].z});
      dis[2] = mk_dis((popo){a2,b2,c2},(popo){ball[j].x,ball[j].y,ball[j].z});
      double s = (dis[0]+dis[1]+dis[2])/2.0;
      double S = sqrt(s*(s-dis[0])*(s-dis[1])*(s-dis[2]));
      double h = (2*S)/dis[0];
      
      if(dis[1]-ball[j].r<=eps ||dis[2]-ball[j].r<=eps) {
	ans+=ball[j].l;
	continue;
      }

      if(abs(sqrt(dis[1]*dis[1]-h*h)+sqrt(dis[2]*dis[2]-h*h)-dis[0]) > eps)continue;
      if(h-ball[j].r<=eps) ans+=ball[j].l;
    }
    cout << ans<<endl;
  }
  return 0;
}