Problem: In 20XX AD, a school competition was held. The tournament has finally left only the final competition. You are one of the athletes in the competition.

The competition you participate in is to compete for the time it takes to destroy all the blue objects placed in the space. Athletes are allowed to bring in competition guns. In the space, there are multiple blue objects, the same number of red objects, and multiple obstacles. There is a one-to-one correspondence between the blue object and the red object, and the blue object must be destroyed by shooting a bullet at the blue object from the coordinates where the red object is placed. The obstacles placed in the space are spherical and the composition is slightly different, but if it is a normal bullet, the bullet will stop there when it touches the obstacle.

The bullet used in the competition is a special bullet called Magic Bullet. This bullet can store magical power, and when the bullet touches an obstacle, it automatically consumes the magical power, and the magic that the bullet penetrates is activated. Due to the difference in the composition of obstacles, the amount of magic required to penetrate and the amount of magic power consumed to activate it are different. Therefore, even after the magic for one obstacle is activated, it is necessary to activate another magic in order to penetrate another obstacle. Also, if the bullet touches multiple obstacles at the same time, magic will be activated at the same time. The amount of magical power contained in the bullet decreases with each magic activation.

While the position and size of obstacles and the amount of magical power required to activate the penetrating magic have already been disclosed, the positions of the red and blue objects have not been disclosed. However, the position of the object could be predicted to some extent from the information of the same competition in the past. You want to save as much magical power as you can, because putting magical power into a bullet is very exhausting. Therefore, assuming the position of the red object and the corresponding blue object, the minimum amount of magical power required to be loaded in the bullet at that time, that is, the magical power remaining in the bullet when reaching the blue object is 0. Let's find the amount of magical power that becomes.

Constraints

* 0 ≤ N ≤ 50
* 1 ≤ Q ≤ 50
* -500 ≤ xi, yi, zi ≤ 500
* 1 ≤ ri ≤ 1,000
* 1 ≤ li ≤ 1016
* -500 ≤ sxj, syj, szj ≤ 500
* -500 ≤ dxj, dyj, dzj ≤ 500
* Obstacles are never stuck in other obstacles
* The coordinates of the object are not inside or on the surface of the obstacle
* Under each assumption, the coordinates of the red object and the blue object do not match.

Input

All inputs are integers. Each number is separated by a single space.


N Q
x1 y1 z1 r1 l1
::
xN yN zN rN lN
sx1 sy1 sz1 dx1 dy1 dz1
::
sxQ syQ szQ dxQ dyQ dzQ


* N is the number of obstacles, and Q is the number of coordinates of the assumed blue and red objects.
* xi, yi, and zi are the x-coordinate, y-coordinate, and z-coordinate that represent the position of the center of the i-th obstacle, respectively.
* ri is the radius of the i-th obstacle.
* li is the amount of magical power consumed by magic to penetrate the i-th obstacle.
* sxj, syj, and szj are the x-coordinate, y-coordinate, and z-coordinate that represent the position of the red object in the jth assumption, respectively.
* dxj, dyj, and dzj are the x-coordinate, y-coordinate, and z-coordinate that represent the position of the blue object in the jth assumption, respectively.

Output

Assuming the position of each pair of red objects and the corresponding blue objects, the amount of magical power to be loaded in the bullet is output on one line, assuming that there are only obstacles, red objects, and one pair of blue objects in space. Let's do it. The bullet is supposed to fly in a straight line from the position of the red object to the position of the blue object, and since the size of the bullet is very small, it is treated as a point.

Examples

Input

5 1
0 10 0 5 2
0 20 0 5 12
0 30 0 5 22
0 40 0 5 32
0 50 0 5 42
0 0 0 0 60 0


Output

110


Input

1 1
10 5 0 5 9
0 0 0 9 12 0


Output

9


Input

5 5
-38 -71 -293 75 1
-158 -38 -405 66 1
-236 -303 157 266 1
316 26 411 190 1
207 -312 -27 196 1
-50 292 -375 -401 389 -389
460 278 409 -329 -303 411
215 -220 -200 309 -474 300
261 -494 -87 -300 123 -463
386 378 486 -443 -64 299


Output

0
2
1
3
0

Solution (in JAVA):

Solution:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static final int INF = 2 << 28;
	static final long INF_L = 2L << 60;
	static final int  MOD = 1000000007;
	static final long MOD_L = 1000000007L;
	static final int[] vx_4 = {1,0,-1,0};
	static final int[] vy_4 = {0,1,0,-1};
	static final int[] vx_5 = {1,0,-1,0,0};
	static final int[] vy_5 = {0,1,0,-1,0};
	static final int[] vx_8 = {1,1,1,0,0,-1,-1,-1};
	static final int[] vy_8 = {1,0,-1,1,-1,1,0,-1};
	static final int[] vx_9 = {1,1,1,0,0,0,-1,-1,-1};
	static final int[] vy_9 = {1,0,-1,1,0,-1,1,0,-1};
	
	static char[] A;
	static char[] B;
	static char[] C;
	public static void main(String[] args) {	
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Geometry3D.Point[] pA = new Geometry3D.Point[n];
		int[]   rA = new int[n];
		long[]   lA = new long[n];
		for(int i = 0; i < n; i++) {
			pA[i] = new Geometry3D.Point(sc.nextInt(), sc.nextInt(), sc.nextInt());
			rA[i] = sc.nextInt();
			lA[i] = sc.nextLong();
		}
		for(int i = 0; i < q; i++) {
			Geometry3D.Point sP = new Geometry3D.Point(sc.nextInt(), sc.nextInt(), sc.nextInt());
			Geometry3D.Point dP = new Geometry3D.Point(sc.nextInt(), sc.nextInt(), sc.nextInt());
			long ans = 0;
			for(int j = 0; j < n; j++) {
				if(Geometry3D.intersectSC(sP, dP, pA[j], rA[j])) {
					ans += lA[j];
				}
			}
			System.out.println(ans);
			
		}
	}
	
	static class Geometry3D {

	    static final double EPS = 1e-3;

	    static boolean approxEquals(double a, double b) {
	        return Math.abs(a - b) < EPS;
	    }

	    static class Point implements Comparable<Point> {

	        final double x, y, z;

	        public Point(double x, double y, double z) {
	            this.x = x;
	            this.y = y;
	            this.z = z;
	        }

	        /** ?????????dot(v1,v2)=|v1||v2|cos?? */
	        double dot(Point p) {
	            return x * p.x + y * p.y + z * p.z;
	        }

	        /** ?????????|cross(v1,v2)|=|v1||v2||sin??| */
	        Point cross(Point p) {
	            return new Point(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
	        }

	        double distanceSqr() {
	            return x * x + y * y + z * z;
	        }

	        double distance() {
	            return Math.sqrt(distanceSqr());
	        }

	        double distanceSqr(Point p) {
	            return subtract(p).distanceSqr();
	        }

	        double distance(Point p) {
	            return subtract(p).distance();
	        }

	        Point add(Point p) {
	            return new Point(x + p.x, y + p.y, z + p.z);
	        }

	        Point multiply(double k) {
	            return new Point(k * x, k * y, k * z);
	        }

	        Point subtract(Point p) {
	            return new Point(x - p.x, y - p.y, z - p.z);
	        }

	        @Override
	        public boolean equals(Object obj) {  // ????????¢??°???Eclipse??§??????????????§?¨?????????????????????????????????°??????
	            if (this == obj) return true;
	            if (obj == null) return false;
	            if (getClass() != obj.getClass()) return false;
	            Point other = (Point) obj;
	            if (!approxEquals(x, other.x)) return false;
	            if (!approxEquals(y, other.y)) return false;
	            if (!approxEquals(z, other.z)) return false;
	            return true;
	        }

	        @Override
	        public int compareTo(Point o) {
	            if (!approxEquals(x, o.x)) return (int) Math.signum(x - o.x);
	            if (!approxEquals(y, o.y)) return (int) Math.signum(y - o.y);
	            if (!approxEquals(z, o.z)) return (int) Math.signum(z - o.z);
	            return 0;
	        }

	        @Override
	        public String toString() {
	            return "(" + x + "," + y + "," + z + ")";
	        }

	    }

	    /**
	     * @param a
	     * @param b
	     * @param c
	     * @param world ????????§?¨?????????´
	     * @return ?????????????????¨??????ccw
	     * @see Geometries2D#ccw(Point, Point, Point)
	     */
	    static int ccw(Point a, Point b, Point c, Point world) {
	        b = b.subtract(a);
	        c = c.subtract(a);
	        double d = world.dot(b.cross(c));
	        if (d > EPS) return +1;                           // counter clockwise
	        if (d + EPS < 0) return -1;                       // clockwise
	        // b??¨c???world????????±????????????????????¨????????????
	        //        if (b.dot(c) + EPS < 0) return +2;                // c--a--b on plane
	        //        if (b.distanceSqr() < c.distanceSqr()) return -2; // a--b--c on plane
	        return 0;                                         // on same projected line
	    }

	    /**
	     * @param n ????????????????????????
	     * @return ????????????p???????????????n??¨??????theta[rad]???????????????????????????
	     * @see http://hooktail.sub.jp/vectoranalysis/vectorRot/
	     */
	    static Point rotate(Point p, Point n, double theta) {
	        Point on = n.multiply(n.dot(p));
	        Point nv = p.subtract(on).multiply(Math.cos(theta));
	        Point qv = p.cross(n).multiply(Math.sin(theta));
	        return on.add(nv).subtract(qv);
	    }

	    /**
	     * @param a ?????¢??????1???
	     * @param n ?????¢?????????????????????
	     * @param p
	     * @return ???p????????¢????????±????????¨?????????
	     */
	    static Point projectOnPlane(Point a, Point n, Point p) {
	        Point ap = p.subtract(a);
	        double t = n.dot(ap) / n.distanceSqr();
	        return p.subtract(n.multiply(t));
	    }

	    /** @return ??´???a??????p????????±????????¨????????? */
	    static Point projectOnLine(Point a1, Point a2, Point p) {
	        Point a = a2.subtract(a1);
	        p = p.subtract(a1);
	        double t = a.dot(p) / a.distanceSqr();
	        return a1.add(a.multiply(t));
	    }

	    static double distancePlaneP(Point a, Point n, Point p) {
	        return projectOnPlane(a, n, p).distance(p);
	    }

	    static double distanceLP(Point a1, Point a2, Point p) {
	        return projectOnLine(a1, a2, p).distance(p);
	    }

	    static double distanceSP(Point a1, Point a2, Point p) {
	        Point r = projectOnLine(a1, a2, p);
	        // ?????±??????????????????????????????????????????p??????????????????????????¢???????????°??????
	        Point ra1 = a1.subtract(r);
	        Point ra2 = a2.subtract(r);
	        double dot = ra1.dot(ra2);
	        if (dot < EPS && approxEquals(dot * dot, ra1.distanceSqr() * ra2.distanceSqr())) return r
	                .distance(p);
	        // ????????§???????????°????????????????????¨????????¢
	        return Math.min(a1.distance(p), a2.distance(p));
	    }

	    /**
	     * ?????????????????¢????????????????????????????????????crosspointLL()????????¶???
	     * 
	     * @see http://mathforum.org/library/drmath/view/51980.html
	     */
	    static double distanceLL(Point a1, Point a2, Point b1, Point b2) {
	        Point n = a2.subtract(a1).cross(b2.subtract(b1));
	        // n???0??????2??´??????????????????????????????????????§??????
	        if (n.distanceSqr() < EPS) return distanceLP(a1, a2, b1);
	        // n????????????b1??????????????¢???????????????a????????´??§???????????§???
	        // ????????????a????????????????????????????????¢???????????¢??????????????¨??????
	        return distancePlaneP(b1, n, a1);
	    }


	    static Point[] crosspointLSphere(Point a1, Point a2, Point c, double r) {
	        Point foot = projectOnLine(a1, a2, c);
	        double footLenSqr = foot.distanceSqr(c);
	        Point dir = a2.subtract(a1);
	        if (approxEquals(r * r, footLenSqr)) {  // ????????§??\????????´???????????????????????????????????????
	            return new Point[] { foot };
	        }
	        if (r * r < footLenSqr) return new Point[0];

	        double len = Math.sqrt(r * r - footLenSqr) / dir.distance();
	        dir = dir.multiply(len);
	        return new Point[] { foot.add(dir), foot.subtract(dir), };
	    }
	     
	    static boolean intersectSC(Point p1, Point p2, Point cP, int rP) {
	        return distanceSP(p1,p2, cP) < rP + EPS;
	    }


	}
		
	
}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
    	if (!hasNext()) throw new NoSuchElementException();
        int n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}