#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

double f(double sx, double sy, double sz, double gx, double gy, double gz){
    return sqrt((sx-gx)*(sx-gx)+(sy-gy)*(sy-gy)+(sz-gz)*(sz-gz));
}

double g(double p, double q, double m, double n){
    return (n*p+m*q)/(m+n);
}


int main(void) {
    int i,j;
    int n,q;
    cin >> n >> q;
    vector<double> x(n),y(n),z(n);
    vector<ll> r(n),l(n);
    rep(i,n) cin >> x[i] >> y[i] >> z[i] >> r[i] >> l[i];
    rep(k,q){
        ll ans = 0;
        double sx,sy,sz,gx,gy,gz;
        cin >> sx >> sy >> sz >> gx >> gy >> gz;
        double dis = f(sx,sy,sz,gx,gy,gz);
        rep(i,n){
            double lb = 0, ub = dis;
            rep(j,100){
                double m1 = (lb+lb+ub)/3.0;
                double m2 = (lb+ub+ub)/3.0;
                double px1 = g(sx,gx,m1,dis-m1);
                double py1 = g(sy,gy,m1,dis-m1);
                double pz1 = g(sz,gz,m1,dis-m1);
                double len1 = f(px1,py1,pz1,x[i],y[i],z[i]);
                double px2 = g(sx,gx,m2,dis-m2);
                double py2 = g(sy,gy,m2,dis-m2);
                double pz2 = g(sz,gz,m2,dis-m2);
                double len2 = f(px2,py2,pz2,x[i],y[i],z[i]);
                if(len1 < len2)ub = m2;
                else lb = m1;
            }
            double px = g(sx,gx,lb,dis-ub);
            double py = g(sy,gy,lb,dis-ub);
            double pz = g(sz,gz,lb,dis-ub);
            double len = f(px,py,pz,x[i],y[i],z[i]);
            //cout << shosu(10) << dis << " " << lb << " " << len << endl;
            if(len <= r[i] + EPS) ans += l[i];
        }
        cout << ans << endl;
    }
}

