using System;
using System.Linq;

namespace ConsoleApp1
{
    internal class Vector3
    {
        public Vector3(double x, double y, double z)
        {
            this.X = x;
            this.Y = y;
            this.Z = z;
        }

        public double X { private set; get; }
        public double Y { private set; get; }
        public double Z { private set; get; }

        public static Vector3 operator -(Vector3 vector1, Vector3 vector2)
        {
            return new Vector3(
                vector1.X - vector2.X,
                vector1.Y - vector2.Y,
                vector1.Z - vector2.Z);
        }

        public static double Distance(Vector3 vector1, Vector3 vector2)
        {
            Vector3 tmp = vector2 - vector1;
            return Math.Sqrt(tmp.Norm());
        }

        public double Norm()
        {
            return
                this.X * this.X +
                this.Y * this.Y +
                this.Z * this.Z;
        }

        public static double DotProduct(Vector3 vector1, Vector3 vector2)
        {
            return
                vector1.X * vector2.X +
                vector1.Y * vector2.Y +
                vector1.Z * vector2.Z;
        }

        public static Vector3 Projection(Vector3 segment1, Vector3 segment2, Vector3 point)
        {
            Vector3 base_ = segment2 - segment1;
            double r = DotProduct(point - segment1, base_) / base_.Norm();
            Vector3 base2 = new Vector3(base_.X * r, base_.Y * r, base_.Z * r);

            return new Vector3(
                segment1.X + base2.X,
                segment1.Y + base2.Y,
                segment1.Z + base2.Z);
        }
    }

    class Obstacle
    {
        public Obstacle(long x, long y, long z, long radius, long magic)
        {
            this.Point = new Vector3(x, y, z);
            this.Radius = radius;
            this.Magic = magic;
        }

        public Vector3 Point { private set; get; }
        public long Radius { private set; get; }
        public long Magic { private set; get; }
    }

    class ObjectPoint
    {
        public ObjectPoint(long blueX, long blueY, long blueZ, long redX, long redY, long redZ)
        {
            this.BlueObject = new Vector3(blueX, blueY, blueZ);
            this.RedObject = new Vector3(redX, redY, redZ);
        }

        public Vector3 BlueObject { private set; get; }
        public Vector3 RedObject { private set; get; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //input
            long[] inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            long obstacle_count = inputNum[0];
            long object_pair = inputNum[1];

            Obstacle[] obstacle_list = new Obstacle[obstacle_count];
            ObjectPoint[] object_list = new ObjectPoint[object_pair];

            for (int lp = 0; lp < obstacle_count; lp++)
            {
                inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                obstacle_list[lp] = new Obstacle(
                    inputNum[0], inputNum[1], inputNum[2],
                    inputNum[3], inputNum[4]);
            }

            for (int lp = 0; lp < object_pair; lp++)
            {
                inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                object_list[lp] = new ObjectPoint(
                    inputNum[0], inputNum[1], inputNum[2],
                    inputNum[3], inputNum[4], inputNum[5]);
            }

            //process
            foreach (var object_ in object_list)
            {
                long magic_count = 0;

                foreach (var obstacle in obstacle_list)
                {
                    /* 
                     * 垂線をおろす
                     * 　垂線の長さがRadius以下であれば接触する
                     */

                    Vector3 projectionPoint = Vector3.Projection(object_.RedObject, object_.BlueObject, obstacle.Point);

                    bool condition1 =
                        object_.RedObject.X <= projectionPoint.X && projectionPoint.X <= object_.BlueObject.X ||
                        object_.RedObject.Y <= projectionPoint.Y && projectionPoint.Y <= object_.BlueObject.Y ||
                        object_.RedObject.Z <= projectionPoint.Z && projectionPoint.Z <= object_.BlueObject.Z;

                    bool condition2 =
                        object_.BlueObject.X <= projectionPoint.X && projectionPoint.X <= object_.RedObject.X ||
                        object_.BlueObject.Y <= projectionPoint.Y && projectionPoint.Y <= object_.RedObject.Y ||
                        object_.BlueObject.Z <= projectionPoint.Z && projectionPoint.Z <= object_.RedObject.Z;

                    if (condition1 || condition2)
                    {
                        double distance = Vector3.Distance(obstacle.Point, projectionPoint);
                        decimal distance2 = new decimal(distance);
                        
                        if (distance2 <= obstacle.Radius)
                        {
                            magic_count += obstacle.Magic;
                        }
                    }
                }

                //output
                Console.WriteLine(magic_count);
            }
        }
    }
}



Measured memory_bytes: 20516