#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(c) (c).begin(), (c).end()

const double tol = 1e-12;

template <class T>
struct Point {
    T x, y, z;
    Point(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
    Point& operator+=(const Point& other) { x += other.x; y += other.y; z += other.z; return *this; }
    Point& operator-=(const Point& other) { x -= other.x; y -= other.y; z -= other.z; return *this; }
    Point& operator*=(const T& alpha) { x *= alpha; y *= alpha; z *= alpha; return *this; }
};

template <class T>
inline Point<T> operator+(const Point<T>& lhs, const Point<T>& rhs) { Point<T> t(lhs); return t += rhs; }
template <class T>
inline Point<T> operator-(const Point<T>& lhs, const Point<T>& rhs) { Point<T> t(lhs); return t -= rhs; }
template <class T>
inline Point<T> operator*(const Point<T>& lhs, const T& rhs) { Point<T> t(lhs); return t *= rhs; }

template <class T>
inline T norm(const Point<T>& p) { return p.x * p.x + p.y * p.y + p.z * p.z; }

template <class T>
inline T abs(const Point<T>& p) { return sqrt(norm(p)); }

template <class T>
inline T dot(const Point<T>& a, const Point<T>& b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

template <class T>
struct Line : vector<Point<T>> {
    Line(const Point<T>& a, const Point<T>& b) : vector<Point<T>>{a, b} {}
    T length() const { return abs((*this)[1] - (*this)[0]); }
};

template <class T>
inline Point<T> projection(const Line<T>& l, const Point<T>& p) {
    const Point<T> q = l[1] - l[0];
    T t = dot(p - l[0], q) / norm(q);
    return l[0] + q * t;
}

template <class T>
struct Segment : Line<T> {
    Segment(const Point<T>& a, const Point<T>& b) : Line<T>(a, b) {}
};

template <class T>
inline bool intersect(const Segment<T>& s, const Point<T>& p) {
    return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < tol;
}

template <class T>
inline T distance(const Segment<T>& s, const Point<T>& p) {
    const Point<T> r = projection(s, p);
    return intersect(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}

template <class T>
struct Sphere : Point<T> {
    T r;
    Sphere(T x_, T y_, T z_, T r_) : Point<T>(x_, y_, z_), r(r_) {}
};

template <class T>
inline bool intersect(const Sphere<T>& sh, const Segment<T>& ls) {
    return distance(ls, Point<T>(sh)) <= sh.r + tol;
}

using point_t = Point<double>;
using segment_t = Segment<double>;
using sphere_t = Sphere<double>;

struct Obstacle : sphere_t {
    long long l;
    Obstacle(double x_, double y_, double z_, double r_, long long l_) : sphere_t(x_, y_, z_, r_), l(l_) {}
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<Obstacle> obstacle;
    rep(i, N) {
        int x, y, z, r; long long l; cin >> x >> y >> z >> r >> l;
        obstacle.emplace_back(x, y, z, r, l);
    }
    while (Q--) {
        int sx, sy, sz, dx, dy, dz; cin >> sx >> sy >> sz >> dx >> dy >> dz;
        segment_t line_of_fire(point_t(sx, sy, sz), point_t(dx, dy, dz));
        cout << accumulate(all(obstacle), 0ll, [&](long long power, const Obstacle& o) {
            return power + (intersect(o, line_of_fire) ? o.l : 0ll);
        }) << endl;
    }
}

Measured memory_bytes: 3116