#include <bits/stdc++.h>
using namespace std;

#define EPS 1e-8

using LLI = long long int;

int N;
int Q;
LLI L[114];
double X[114];
double Y[114];
double Z[114];
double R[114];

int main() {
  scanf("%d%d", &N, &Q);
  for (int i=0; i<N; i++) {
    scanf("%lf%lf%lf%lf%lld", &X[i], &Y[i], &Z[i], &R[i], &L[i]);
  }

  while (Q--) {
    double sx, sy, sz;
    double dx, dy, dz;
    scanf("%lf%lf%lf%lf%lf%lf", &sx, &sy, &sz, &dx, &dy, &dz);
    LLI ans = 0;
    for (int j=0; j<N; j++) {
      double low = 0;
      double high = 1;
      for (int i=0; i<60; i++) {
        double midl = (low*2+high)/3;
        double midr = (low+high*2)/3;
        double xl = sx*midl + dx*(1-midl);
        double yl = sy*midl + dy*(1-midl);
        double zl = sz*midl + dz*(1-midl);
        double dl = (X[j]-xl)*(X[j]-xl) + (Y[j]-yl)*(Y[j]-yl) + (Z[j]-zl)*(Z[j]-zl);
        double xr = sx*midr + dx*(1-midr);
        double yr = sy*midr + dy*(1-midr);
        double zr = sz*midr + dz*(1-midr);
        double dr = (X[j]-xr)*(X[j]-xr) + (Y[j]-yr)*(Y[j]-yr) + (Z[j]-zr)*(Z[j]-zr);
        if (dl > dr) low = midl;
        else high = midr;
      }

      double mid = low;
      double x = sx*mid + dx*(1-mid);
      double y = sy*mid + dy*(1-mid);
      double z = sz*mid + dz*(1-mid);
      double d = (X[j]-x)*(X[j]-x) + (Y[j]-y)*(Y[j]-y) + (Z[j]-z)*(Z[j]-z);
      if (-EPS <= R[j]*R[j]-d) ans += L[j];
    }
    printf("%lld\n", ans);
  }
}