#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

#define eps 1e-10

int main() {

  long long int n, q;
  cin >> n >> q;

  vector< long long int > x, y, z, r, l;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in_x, in_y, in_z, in_r, in_l;
    cin >> in_x >> in_y >> in_z >> in_r >> in_l;
    x.push_back( in_x );
    y.push_back( in_y );
    z.push_back( in_z );
    r.push_back( in_r );
    l.push_back( in_l );

  }

  vector< long long int > sx, sy, sz, dx, dy, dz;

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

    long long int in_x, in_y, in_z;
    cin >> in_x >> in_y >> in_z;
    sx.push_back( in_x );
    sy.push_back( in_y );
    sz.push_back( in_z );
    cin >> in_x >> in_y >> in_z;
    dx.push_back( in_x );
    dy.push_back( in_y );
    dz.push_back( in_z );

  }

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

    long long int ans = 0;

    long long int vx = dx[i] - sx[i];
    long long int vy = dy[i] - sy[i];
    long long int vz = dz[i] - sz[i];

    for ( long long int j = 0; j < n; j++ ) {

      long long int vsx = x[j] - sx[i];
      long long int vsy = y[j] - sy[i];
      long long int vsz = z[j] - sz[i];
      long long int vdx = x[j] - dx[i];
      long long int vdy = y[j] - dy[i];
      long long int vdz = z[j] - dz[i];

      long long int vs = vsx * vx + vsy * vy + vsz * vz;
      long long int vd = vdx * -vx + vdy * -vy + vdz * -vz;

      if ( vs > 0 && vd > 0 ) {

	double a = sqrt( vsx * vsx + vsy * vsy + vsz * vsz );
	double b = sqrt( vx * vx + vy * vy + vz * vz );
	double c = sqrt( vdx * vdx + vdy * vdy + vdz * vdz );

	double h = sqrt( ( a * b * 2 + c * c - a * a - b * b ) * ( a * b * 2 - ( c * c - a * a - b * b ) ) ) / ( b * 2 );

	if ( h - r[j] <= eps ) ans += l[j];

      }

    }

    cout << ans << endl;

  }


  return 0;

}