#include <bits/stdc++.h>
using namespace std;
struct st {
  double x, y, z;
};
st v[101];
double a1, a2, a3, sx, sy, sz, gx, gy, gz;
int a4, a5, t[101], p[101];
double ch(int q) {
  double px = v[q].x, py = v[q].y, pz = v[q].z;
  double t1 = sqrt((sx - gx) * (sx - gx) + (sy - gy) * (sy - gy) +
                   (sz - gz) * (sz - gz));
  double t2 = sqrt((px - gx) * (px - gx) + (py - gy) * (py - gy) +
                   (pz - gz) * (pz - gz));
  double t3 = sqrt((sx - px) * (sx - px) + (sy - py) * (sy - py) +
                   (sz - pz) * (sz - pz));
  double s = (t1 + t2 + t3) / 2;
  double h = sqrt(s * (s - t1) * (s - t2) * (s - t3)) * 2 / t1;
  if (abs(sqrt(t2 * t2 - h * h) + sqrt(t3 * t3 - h * h) - t1) > 0.1)
    return 10e8;
  return h;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a1 >> a2 >> a3 >> a4 >> a5;
    v[i].x = a1;
    v[i].y = a2;
    v[i].z = a3;
    t[i] = a4;
    p[i] = a5;
  }
  while (m--) {
    int sum = 0;
    cin >> sx >> sy >> sz >> gx >> gy >> gz;
    for (int i = 0; i < n; i++) {
      double h = ch(i);
      if (h < (double)(t[i])) sum += p[i];
    }
    cout << sum << endl;
  }
}
