#include<bits/stdc++.h>
using namespace std;
#define D 1e-9
typedef struct _vec{
    double x, y, z;
} vec;

double Dis(vec A, vec B){
    double dis = (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y) + (A.z-B.z)*(A.z-B.z);
    //cout << dis << " o " <<  endl;
    dis = pow(dis, 0.5);
    //cout << dis << " o " <<  endl;    
    return dis;
}

double norm(vec A, vec B){             //内積
    double res;
    res = A.x*B.x + A.y*B.y + A.z*B.z;   

    return res;
}

vec tanni(vec A){                   //単位ベクトルを返す
    double dis = A.x*A.x + A.y*A.y + A.z*A.z;
    dis = pow(dis, 0.5);
    vec res;
    res.x = A.x / dis;
    res.y = A.y / dis;
    res.z = A.z / dis;

    return res;    
}

vec houkou(vec A, vec B){             //方向ベクトルを返す
    vec res;
    //cout << B.x << " " << A.x << endl;
    res.x = B.x - A.x;
    res.y = B.y - A.y;
    res.z = B.z - A.z;
    return res;
}

int main(){

    /*vec V1, V2;
    V1.x = 3;
    V1.y = 4;
    V1.z = 5;
    V2.x = 6;
    V2.y = 3;
    V2.z = 8;

    cout << norm(V1, V2) << endl;
    cout << Dis(V1, V2) << endl;
    vec V3 = tanni(V1);
    cout << V3.x << " " << V3.y << " " << V3.z << endl;
    vec V4 = houkou(V1, V2);
    cout << V4.x << " " << V4.y << " " << V4.z << endl;*/
    

    int n, q; cin >> n >> q;
    vector<vec> obj(n);
    vector<vec> blue(q);
    vector<vec> red(q);    
    vector<double> r(n);
    vector<long long> l(n);

    for(int i = 0; i < n; i++){
        double a, b, c, d, e; cin >> a >> b >> c >> d >> e;
        obj[i].x = a;
        obj[i].y = b;
        obj[i].z = c;
        r[i] = d;
        l[i] = e;                
    }

    for(int i = 0; i < q; i++){
        double a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
        blue[i].x = d;
        blue[i].y = e;
        blue[i].z = f;
        red[i].x = a;
        red[i].y = b;
        red[i].z = c;        
    }



    for(int i = 0; i < q; i++){

        long long ans = 0;

        for(int j = 0; j < n; j++){
            //j個目の障害物とはどうですか
            vec H;
            H.x = red[i].x;
            H.y = red[i].y;
            H.z = red[i].z;            

            vec u;
            u = houkou(red[i], blue[i]);
            //cout << u.x << " " << u.y << " " << u.z << endl;            
            u = tanni(u);
            //cout << u.x << " " << u.y << " " << u.z << endl;
            vec a;
            a.x = obj[j].x - red[i].x;
            a.y = obj[j].y - red[i].y;
            a.z = obj[j].z - red[i].z;
            //cout << a.x << " " << a.y << " " <<  a.z << endl;           
            double _norm = norm(a, u);
            //cout << _norm << endl;
            vec w;
            w.x = _norm*u.x;
            w.y = _norm*u.y;
            w.z = _norm*u.z;
            //cout << endl;
            //cout << H.x << " " << H.y << " " << H.z << endl;
            //cout << w.x << " " << w.y << " " << w.z << endl;
            H.x += w.x;
            H.y += w.y;
            H.z += w.z;

            //cout << H.x << " " << H.y << " " << H.z << endl;
            //cout << obj[j].x << " " << obj[j].y << " " << obj[j].z << endl;

            double _dis = Dis(H, obj[j]);
            //cout << j << " " << _dis << endl;
            //cout << _dis << endl;

            bool flag = (red[i].x <= H.x + D && H.x - D <= blue[i].x) || (blue[i].x <= H.x + D && H.x - D <= red[i].x);                         //線分上にあるか

            if(_dis <= r[j] + D && flag) ans += l[j];            
            //cout << ans << endl;
        
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3384