/*
 * 2641.cc: Magic Bullet
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;

/* typedef */

typedef long long ll;

template <typename T>
struct Pt3d {
  T x, y, z;

  Pt3d() {}
  Pt3d(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
  Pt3d(const Pt3d& pt) : x(pt.x), y(pt.y), z(pt.z) {}

  Pt3d<T> operator+(const Pt3d pt) const {
    return Pt3d<T>(x + pt.x, y + pt.y, z + pt.z);
  }
  Pt3d<T> operator-() const {
    return Pt3d<T>(-x, -y, -z);
  }
  Pt3d<T> operator-(const Pt3d pt) const {
    return Pt3d<T>(x - pt.x, y - pt.y, z - pt.z);
  }
  T dot(Pt3d v) const { return x * v.x + y * v.y + z * v.z; }
  Pt3d<T> cross(Pt3d v) const {
    return Pt3d<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
  }
  T d2() { return x * x + y * y + z * z; }
  double d() { return sqrt(d2()); }

  void print(string format) {
    printf(("(" + format + ", " + format + ", " + format + ")").c_str(),
           x, y, z);
  }
  void print() { print("%.6lf"); }
};

typedef Pt3d<double> pt3d;

/* global variables */

pt3d cps[MAX_N];
double rs[MAX_N];
ll ls[MAX_N];

/* subroutines */

double dist_p_seg(pt3d &s0, pt3d &s1, pt3d &p) {
  pt3d v = s1 - s0, p0 = p - s0, p1 = p - s1;
  double d0 = v.dot(p0), d1 = v.dot(p1);

  if (d0 <= 0.0) return p0.d();
  if (d1 >= 0.0) return p1.d();
  return sqrt(p0.d2() - d0 * d0 / v.d2());
}

/* main */

int main() {
  int n, qn;
  cin >> n >> qn;

  for (int i = 0; i < n; i++)
    cin >> cps[i].x >> cps[i].y >> cps[i].z >> rs[i] >> ls[i];

  while (qn--) {
    pt3d sp, gp;
    cin >> sp.x >> sp.y >> sp.z >> gp.x >> gp.y >> gp.z;

    ll sum = 0;
    for (int i = 0; i < n; i++) {
      double d = dist_p_seg(sp, gp, cps[i]);
      if (d <= rs[i]) sum += ls[i];
      if (false) {
	sp.print(); putchar('-'); gp.print(); printf(" : "); cps[i].print();
	printf(" = %lf\n", d);
      }
    }
    printf("%lld\n", sum);
  }
  return 0;
}