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

#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

const double EPS = 1e-10;
#define equals(a,b) (fabs((a)-(b)) < EPS)

class Point {
public:
	double x, y, z;
	Point(double x = 0, double y = 0, double z = 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); }
	bool operator<(const Point &p)const {
		if (x < p.x)return true;
		if (x > p.x)return false;
		if (y < p.y)return true;
		if (y > p.y)return false;
		if (z < p.z)return true;
		return false;
	}
	bool operator==(const Point &p)const { return equals(x, p.x) && equals(y, p.y) && equals(z, p.z); }

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

};
inline ostream &operator << (ostream &os, const Point &p) { os << p.x << " " << p.y << " " << p.z; return os; }
inline istream &operator >> (istream &is, Point &p) { double x, y, z; is >> x >> y >> z; p = Point(x, y, z); return is; }

using Vector = Point;

class Segment {
public:
	Point p1, p2;
	Segment(Point p1 = Point(), Point p2 = Point()) :p1(p1), p2(p2) {}
};
using Line = Segment;

//???
class Sphere {
public:
	Point c;
	double r;
	int w;
	Sphere(Point c = Point(), double r = 1.0) :c(c), r(r) {};
};

//http://www.math.s.chiba-u.ac.jp/~yasuda/Chiba/Lec/naiseki.pdf
//?????? dot product
double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
//?????? cross product
Vector cross(Vector a, Vector b) {
	Vector ret;
	ret.x = a.y*b.z - a.z*b.y;
	ret.y = a.z*b.x - a.x*b.z;
	ret.z = a.x*b.y - a.y*b.x;
	return ret;
}

//?°???±
Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}

//2??????????????¢
double get_distance(Point a, Point b) { return (a - b).abs(); }
//http://www.sousakuba.com/Programming/gs_dot_line_distance.html
//??´?????¨???????????¢
double get_distance_LP(Line l, Point p) { return cross(l.p2 - l.p1, p - l.p1).abs() / (l.p2 - l.p1).abs(); }
//????????¨???????????¢
double get_distance_SP(Segment s, Point p) {
	if (dot(s.p2 - s.p1, p - s.p1) < 0.0)return get_distance(p, s.p1);
	if (dot(s.p1 - s.p2, p - s.p2) < 0.0)return get_distance(p, s.p2);
	return get_distance_LP(s, p);
}

//?????¨?????????????????????
bool intersect(Sphere SP, Segment S) {
	return SP.r + EPS >= get_distance_SP(S, SP.c);
}

//?????¨??´????????????
pair<Point, Point> get_cross_points(Sphere SP, Line L) {
	assert(intersect(SP, L));
	Vector pr = project(L, SP.c);
	Vector e = (L.p2 - L.p1) / (L.p2 - L.p1).abs();
	double base = sqrt(SP.r*SP.r - (pr - SP.c).norm());
	return make_pair(pr + e*base, pr - e*base);
}

signed main() {
	int N, Q; cin >> N >> Q;
	vector<Sphere> Spheres(N);
	rep(i, 0, N)cin >> Spheres[i].c >> Spheres[i].r >> Spheres[i].w;
	rep(i, 0, Q) {
		Point s, d; cin >> s >> d;
		Segment S = Segment(s, d);
		int ans = 0;
		for (Sphere &SP : Spheres)
			if (intersect(SP, S))
				ans += SP.w;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3224