#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

#define double long double

namespace point_3d {

double const EPS = 1e-7;  // !!! DO CHECK EPS !!!

struct P3 {
  double x, y, z;
  P3(): x(0), y(0), z(0){}
  P3(double x, double y, double z): x(x), y(y), z(z){};
  P3 operator + (P3 const& r) const { return P3(x+r.x, y+r.y, z+r.z); }
  P3 operator - (P3 const& r) const { return P3(x-r.x, y-r.y, z-r.z); }
  P3 operator * (double k) const { return P3(x * k, y * k, z * k); }
  P3 operator / (double k) const { return P3(x / k, y / k, z / k); }
};

double dot(P3 const& l, P3 const& r) { return l.x*r.x + l.y*r.y + l.z*r.z; }
P3 cross(P3 const& l, P3 const& r) { return P3(l.y*r.z - l.z*r.y, l.z*r.x - l.x*r.z, l.x*r.y - l.y*r.x); }  // not verified

double norm(P3 const& p) { return p.x*p.x + p.y*p.y + p.z*p.z; }
double abs(P3 const& p) { return sqrt(p.x*p.x + p.y*p.y + p.z*p.z); }
double cos(P3 const& l, P3 const& r) { return dot(l, r) / (abs(l) * abs(r)); }
double angle(P3 const& l, P3 const& r) { return acos(cos(l, r)); }  // not verified

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

struct Line: public pair<P3, P3> {
  P3 const& operator[](int idx) const { return idx == 0 ? first : second; }
  P3& operator[](int idx) { return idx == 0 ? first : second; }
};
typedef Line Segment;

double distance_lp(Line const& l, P3 const& p) {  // not verified
  return abs(p - l[0]) * sin(angle(l[1] - l[0], p - l[0]));
}

P3 projection(Line const& l, P3 const& p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + (l[0]-l[1]) * t;
}

bool intersect_sp(Segment const& s, P3 const& p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

double distance_sp(Segment const& s, P3 const& p) {
  P3 const r = projection(s, p);
  if(intersect_sp(s, r)) return abs(r - p); // ?°???±?????????????????????????????????
  return min(abs(s[0] - p), abs(s[1] - p));
}

}
using namespace point_3d;

int main() {

  int N, Q; cin >> N >> Q;
  vector<tuple<P3, double, double>> os;
  rep(i, N) {
    P3 p; double r; ll l; cin >> p >> r >> l;
    os.emplace_back(p, r, l);
  }

  rep(_, Q) {
    ll ans = 0;
    Segment beam; cin >> beam[0] >> beam[1];

    auto intersect_segment_sphere = [&](int oidx) {
      P3 c; double r; ll _; tie(c, r, _) = os[oidx];
      return distance_sp(beam, c) <= r + EPS;
    };

    rep(i, N) {
      if(intersect_segment_sphere(i)) {
        ans += get<2>(os[i]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3316