//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

const double mEPS = 1e-10;
const LL INF = 1e9;

//???????????????????????????
class Point{
public:
  double x, y, z;

  Point(LL x = 0.0, LL y = 0.0, LL z = 0.0) : x(x), y(y),z(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 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()*1.); }
  LL norm(){ return x*x + y*y + z*z; }

  //EPS??????????°??????????
  bool operator == (const Point &p) const {
	return fabs(x - p.x) < mEPS && fabs(y - p.y) < mEPS;
  }

};

class Segment{
public:
	Point p1, p2;
};

class Circle{
public:
	Point c;
	double r;
};
//???????????¨????????±???
typedef Point Vector;
//???????????´?????¨????????±???
typedef Segment Line;

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

LL cross(Vector a, Vector b){
  Point p(a.y*b.z-b.y*a.z, a.z*b.x-b.z*a.x, a.x*b.y-b.x*a.y);
  return p.norm();
  //  return a.x*b.y - a.y*b.x;
}
LL getDistanceLP(Line l, Point p){
	return abs(cross(l.p2 - l.p1, p - l.p1) / (l.p2 - l.p1).norm());
}

LL getDistanceSP(Segment s, Point p){
  if (dot(s.p2 - s.p1, p - s.p1) < 0) return INF; //(p - s.p1).abs();
  if (dot(s.p1 - s.p2, p - s.p2) < 0) return INF; //(p - s.p2).abs();
  return getDistanceLP(s, p);
}


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, Q; cin >> N >> Q;
  vector<Point> ps(N);
  vector<LL> rs(N), ls(N);
  REP(i,N) cin >> ps[i].x >> ps[i].y >> ps[i].z >> rs[i] >> ls[i];

  REP(i,Q){
	LL ans = 0;
	int sx, sy, sz, dx, dy, dz;
	cin >> sx >> sy >> sz >> dx >> dy >> dz;
	Segment s;
	s.p1 = Point(sx,sy,sz);
	s.p2 = Point(dx,dy,dz);
	REP(i,N){
	  if(getDistanceSP(s, ps[i]) <= rs[i]*rs[i]) ans += ls[i];
	}
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1240