#include <iostream>
#include <vector>
#include <cmath>

#define vec vector
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long

using namespace std;

double sx, sy, sz, dx, dy, dz;

int outside(double a, double b, double c)
{
	double x, y, z;
	x = sqrt((a - sx) * (a - sx) + (b - sy) * (b - sy) + (c - sz) * (c - sz));
	y = sqrt((a - dx) * (a - dx) + (b - dy) * (b - dy) + (c - dz) * (c - dz));
	z = sqrt((sx - dx) * (sx - dx) + (sy - dy) * (sy - dy) + (sz - dz) * (sz - dz));

	double keep1 = (x * x + z * z - y * y) / (2 * x * z);
	double keep2 = (y * y + z * z - x * x) / (2 * y * z);

	if (keep1 < 0) return 1;
	else if (keep2 < 0) return 2;
	else return 0;
}


int main(void)
{
	int n, q;
	cin >> n >> q;

	vec<double> x(n), y(n), z(n), r(n);
	vec<ll> l(n);

	rep(i, n) cin >> x[i] >> y[i] >> z[i] >> r[i] >> l[i];

	rep(i, q) {
		cin >> sx >> sy >> sz >> dx >> dy >> dz;
		ll ans = 0;
		rep(j, n) {
			int w = outside(x[j], y[j], z[j]);
			if (w == 1) {
				if ((x[j] - sx) * (x[j] - sx) + (y[j] - sy) * (y[j] - sy) + (z[j] - sz) * (z[j] - sz) <= r[j] * r[j]) ans += l[j];
			}
			else if (w == 2) {
				if ((x[j] - dx) * (x[j] - dx) + (y[j] - dy) * (y[j] - dy) + (z[j] - dz) * (z[j] - dz) <= r[j] * r[j]) ans += l[j];
			}
			else {
				double v1 = sx - dx;
				double v2 = sy - dy;
				double v3 = sz - dz;
				double v = v1 * v1 + v2 * v2 + v3 * v3;
				double t = (v1 * (x[j] - sx) + v2 * (y[j] - sy) + v3 * (z[j] - sz)) / v;
				if ((x[j] - sx) * (x[j] - sx) + (y[j] - sy) * (y[j] - sy) + (z[j] - sz) * (z[j] - sz) - v * t * t <= r[j] * r[j]) ans += l[j];
			}
		}

		cout << ans << endl;
	}
	return 0;
}