#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const double eps = 1e-10;

struct Point {
  double x, y, z;
  Point() {}
  Point(double x, double y, double z) : x(x), y(y), z(z) {}
  Point operator+(const Point& p) const { return Point(x + p.x, y + p.y, z + p.z); }
  Point operator-(const Point& p) const { return Point(x - p.x, y - p.y, z - p.z); }
  Point operator*(double k) const { return Point(x * k, y * k, z * k); }
  friend istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y >> p.z; }
};

double abs(const Point& a) {
  return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
}

double dot(const Point& a, const Point& b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

Point cross(const Point& a, const Point& b) {
  return Point(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

double distanceSP(const Point& a, const Point& b, const Point& p) {
  return abs(cross(b - a, p - a)) / abs(b - a);
}

struct Circle {
  Point c;
  double r;
  ll l;
  Circle() {}
  friend istream& operator>>(istream& is, Circle& c) { return is >> c.c >> c.r >> c.l; }
};

bool isThrough(Point& a, Point& b, Circle& c) {
  if (dot(b - a, c.c - a) < -eps) return abs(c.c - a) - c.r < eps;
  if (dot(a - b, c.c - b) < -eps) return abs(c.c - b) - c.r < eps;
  return distanceSP(a, b, c.c) - c.r < eps;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n, q;
  cin >> n >> q;

  vector<Circle> cs(n);
  for (int i = 0; i < n; i++) {
    cin >> cs[i];
  }

  for (int i = 0; i < q; i++) {
    Point a, b;
    cin >> a >> b;

    ll ans = 0;
    for (int j = 0; j < n; j++) {
      if (isThrough(a, b, cs[j])) ans += cs[j].l;
    }
    cout << ans << endl;
  }

  return 0;
}
