Initially, two non-touching spheres of radii R1 and R2 are lying in space at rest. Both of them are then given accelerations a1 and a2 respectively at time=0. Find whether they will ever come in contact. Their initial positions are represented as (x1,y1,z1) and (x2,y2,z2) respectively. Accelerations have respective components in 3D. They are represented as (a1_{i},a1_{j},a1_{k}) and (a2_{i},a2_{j},a2_{k}) respectively.

Input Format 

The first line contains T, the number of test cases. 

Each test case consists of five lines, where the first line contains R1 and R2. The next two lines contain position and acceleration of the first sphere. The next two lines after this contain position and acceleration of the second sphere. All numbers in input are integers. 

Output Format 

For each test case, print YES, if the spheres come in contact. Otherwise, print NO (quotes for clarity).  

Constraints 

1 ≤ T ≤ 10^{4} 

1 ≤ R1, R2 ≤ 10^{2} 

-10^{2} ≤ x1, y1, z1 , x2 , y2 , z2 ≤ 10^{2} 

-10^{2} ≤ a1_{i} , a1_{j} , a1_{k} , a2_{i} , a2_{j} , a2_{k} ≤ 10^{2}     

Sample input  

2
1 2
0 0 0
-1 0 0
4 0 0
1 0 0
1 2
0 0 0
100 0 0
4 0 0
0 0 0

Sample output  

NO
YES

Explanation 

For first testcase, both spheres go in opposite directions, so they'll never come in contact. 

For second testcase, second sphere is not moving while first sphere is accelerating towards the second sphere. So they come in contact.

Difficulty: MEDIUM
Tags: Geometry

Starter code:

Solutions:
from math import sqrt
read = lambda : map(float, input().split())
T = int(input())
for t in range(T):
	(R1, R2) = read()
	(x1, y1, z1) = read()
	(a1i, a1j, a1k) = read()
	(x2, y2, z2) = read()
	(a2i, a2j, a2k) = read()
	a = ((a1i - a2i) * (a1i - a2i) + (a1j - a2j) * (a1j - a2j) + (a1k - a2k) * (a1k - a2k)) / 4
	b = (x1 - x2) * (a1i - a2i) + (y1 - y2) * (a1j - a2j) + (z1 - z2) * (a1k - a2k)
	c = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)
	f = lambda t: a * t * t + b * t + c
	d = -b / a / 2
	D = f(d) if d >= 0 else f(0)
	if sqrt(D) <= R1 + R2:
		print('YES')
	else:
		print('NO')


import sys, math
inp = sys.stdin.read()
inp = inp.split(sep='\n')
T = int(inp.pop(0))

def CheckIneq(a, b, c):
	Dis = b ** 2 - 4 * a * c
	if Dis < 0:
		return False
	elif -b + math.sqrt(Dis) < 0 and -b - math.sqrt(Dis) < 0:
		return False
	else:
		return True
Dims = 3
for i in range(T):
	Data = []
	for l in range(5):
		Data.append(inp[i * 5 + l].split())
		for k in range(len(Data[-1])):
			Data[-1][k] = int(Data[-1][k])
	Rsum = sum(Data[0])
	rs = []
	ars = []
	for i in range(Dims):
		rs.append(Data[3][i] - Data[1][i])
		ars.append(Data[4][i] - Data[2][i])
	a = 0
	b = 0
	c = -Rsum ** 2 * 4
	for i in range(Dims):
		a += ars[i] ** 2
		b += ars[i] * rs[i] * 4
		c += rs[i] ** 2 * 4
	if not CheckIneq(a, b, c):
		if c <= 0:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	[R1, R2] = list(map(float, input().split()))
	[x1, y1, z1] = list(map(float, input().split()))
	[a1x, a1y, a1z] = list(map(float, input().split()))
	[x2, y2, z2] = list(map(float, input().split()))
	[a2x, a2y, a2z] = list(map(float, input().split()))
	(px, py, pz) = (x1 - x2, y1 - y2, z1 - z2)
	(ax, ay, az) = (a1x - a2x, a1y - a2y, a1z - a2z)
	da = ax * ax + ay * ay + az * az
	dp = px * px + py * py + pz * pz
	co = ax * px + ay * py + az * pz
	x = 0.0
	if da != 0:
		x = -co / da
	x = max(x, 0)
	dis = (da * x * x + 2 * co * x + dp) ** 0.5
	if dis <= R1 + R2:
		print('YES')
	else:
		print('NO')


T = int(input())
for test_case in range(T):
	(R1, R2) = (int(n) for n in input().split())
	x1 = [int(n) for n in input().split()]
	a1 = [int(n) for n in input().split()]
	x2 = [int(n) for n in input().split()]
	a2 = [int(n) for n in input().split()]
	dx = [0] * 3
	da = [0] * 3
	da_len2 = 0
	dot = 0
	for i in range(3):
		dx[i] = x1[i] - x2[i]
		da[i] = a1[i] - a2[i]
		da_len2 += da[i] * da[i]
		dot += dx[i] * da[i]
	if dot >= 0:
		print('NO')
		continue
	s = 0
	for i in range(3):
		a = dx[i] * da_len2 - da[i] * dot
		s += a * a
	if s <= da_len2 * da_len2 * (R1 + R2) * (R1 + R2):
		print('YES')
	else:
		print('NO')


import sys
mag = lambda p: sum((x * x for x in p)) ** 0.5
dist = lambda p1, p2: mag([y - x for (x, y) in zip(p1, p2)])
T = int(sys.stdin.readline())
for _ in range(T):
	(R1, R2) = list(map(int, sys.stdin.readline().split()))
	p1 = list(map(int, sys.stdin.readline().split()))
	a1 = list(map(int, sys.stdin.readline().split()))
	p2 = list(map(int, sys.stdin.readline().split()))
	a2 = list(map(int, sys.stdin.readline().split()))
	dp = [y - x for (x, y) in zip(p1, p2)]
	da = [y - x for (x, y) in zip(a1, a2)]
	t2 = -2.0 * sum((p * a for (p, a) in zip(dp, da))) / sum((a * a for a in da))
	if t2 >= 0:
		print('YES' if mag([p + a * t2 / 2 for (p, a) in zip(dp, da)]) <= R1 + R2 else 'NO')
	else:
		print('NO')


n = int(input())

def read():
	i = input()
	return map(int, i.split())

def dist(a, b):
	return sum([(x - y) ** 2 for (x, y) in zip(a, b)])

def dot(a, b):
	return sum((x * y for (x, y) in zip(a, b)))

def mul(k, a):
	return list([k * x for x in a])

def plus(a, b):
	return list([x + y for (x, y) in zip(a, b)])
for _ in range(n):
	(r1, r2) = read()
	(x1, y1, z1) = read()
	(a1x, a1y, a1z) = read()
	(x2, y2, z2) = read()
	(a2x, a2y, a2z) = read()
	pos = [x1 - x2, y1 - y2, z1 - z2]
	acc = [a1x - a2x, a1y - a2y, a1z - a2z]
	t = -2 * dot(pos, acc) / dot(acc, acc)
	if t > 0:
		t = t ** 0.5
		s = plus(pos, mul(t * t / 2, acc))
		d = dot(s, s)
		if dot(s, s) < (r1 + r2) ** 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def dotProd(A, B):
	return A[0] * B[0] + A[1] * B[1] + A[2] * B[2]

def collide(A, B):
	R_ = A[0] + B[0]
	S_ = (B[1][0] - A[1][0], B[1][1] - A[1][1], B[1][2] - A[1][2])
	A_ = (B[2][0] - A[2][0], B[2][1] - A[2][1], B[2][2] - A[2][2])
	R = R_ * R_
	SS = dotProd(S_, S_)
	SA = dotProd(S_, A_)
	AA = dotProd(A_, A_)
	a = AA / 4
	b = SA
	c = SS - R
	delta = b * b - 4 * a * c
	if delta < 0:
		return False
	if b > 0 and delta < b * b:
		return False
	return True
T = int(input())
for _ in range(T):
	(R1, R2) = [int(_) for _ in input().split()]
	(x1, y1, z1) = [int(_) for _ in input().split()]
	(ax1, ay1, az1) = [int(_) for _ in input().split()]
	(x2, y2, z2) = [int(_) for _ in input().split()]
	(ax2, ay2, az2) = [int(_) for _ in input().split()]
	if collide((R1, (x1, y1, z1), (ax1, ay1, az1)), (R2, (x2, y2, z2), (ax2, ay2, az2))):
		print('YES')
	else:
		print('NO')


from sys import stdin as cin, stdout as cout
from math import sqrt
from fractions import gcd
for t in range(int(cin.readline())):
	(r1, r2) = map(int, cin.readline().split())
	(x1, y1, z1) = map(int, cin.readline().split())
	(a1, a2, a3) = map(int, cin.readline().split())
	(x2, y2, z2) = map(int, cin.readline().split())
	(a4, a5, a6) = map(int, cin.readline().split())
	a = ((a1 - a4) ** 2 + (a2 - a5) ** 2 + (a3 - a6) ** 2) / 4
	b = (x1 - x2) * (a1 - a4) + (y1 - y2) * (a2 - a5) + (z1 - z2) * (a3 - a6)
	c = -1 * ((r1 + r2) ** 2 - (x1 - x2) ** 2 - (y1 - y2) ** 2 - (z1 - z2) ** 2)
	k = b * b - 4 * a * c
	if k < 0:
		print('NO')
	elif (-b - sqrt(k)) / (2 * a) >= 0 or (-b + sqrt(k)) / (2 * a) >= 0:
		print('YES')
	else:
		print('NO')


from math import sqrt

def minimum(p1, p2, a1, a2):
	a = 0
	c = 0
	for i in range(3):
		a = a + (a2[i] - a1[i]) ** 2
	a = a / 2
	for i in range(3):
		c = c + (p2[i] - p1[i]) * (a2[i] - a1[i])
	if -4 * a * c > 0:
		t = sqrt(-4 * a * c)
		t = t / 2
		t = t / a
		return t
	else:
		return 0

def distance(p1, p2, a1, a2, t):
	d1 = 0
	d2 = 0
	total = 0
	for i in range(3):
		d1 = p1[i] + 0.5 * a1[i] * t ** 2
		d2 = p2[i] + 0.5 * a2[i] * t ** 2
		total = total + (d2 - d1) ** 2
	return sqrt(total)
T = int(input())
a1 = []
a2 = []
p1 = []
p2 = []
rad = []
for i in range(T):
	rad = str(input()).split(' ')
	p1 = str(input()).split(' ')
	a1 = str(input()).split(' ')
	p2 = str(input()).split(' ')
	a2 = str(input()).split(' ')
	a1 = [int(x) for x in a1]
	p1 = [int(x) for x in p1]
	a2 = [int(x) for x in a2]
	p2 = [int(x) for x in p2]
	time = minimum(p1, p2, a1, a2)
	dist = distance(p1, p2, a1, a2, time)
	if int(rad[0]) + int(rad[1]) < dist:
		print('NO')
	else:
		print('YES')


def dis(p1, p2):
	return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 + (p1[2] - p2[2]) ** 2

def disWhenT(p1, p2, a1, a2, t):
	p3 = [p1[i] + 0.5 * a1[i] * t for i in range(0, 3)]
	p4 = [p2[i] + 0.5 * a2[i] * t for i in range(0, 3)]
	return dis(p3, p4)
T = int(input())
for i in range(0, T):
	R = [int(x) for x in input().split()]
	p1 = [int(x) for x in input().split()]
	a1 = [int(x) for x in input().split()]
	p2 = [int(x) for x in input().split()]
	a2 = [int(x) for x in input().split()]
	maxdis = (R[0] + R[1]) ** 2
	if dis(p1, p2) <= maxdis:
		print('YES')
		continue
	u = [p1[i] - p2[i] for i in range(0, 3)]
	w = [0.5 * (a1[i] - a2[i]) for i in range(0, 3)]
	z = u[0] * w[0] + u[1] * w[1] + u[2] * w[2]
	if z >= 0:
		print('NO')
		continue
	t = -1.0 * z / (w[0] ** 2 + w[1] ** 2 + w[2] ** 2)
	mindis = disWhenT(p1, p2, a1, a2, t)
	if mindis <= maxdis:
		print('YES')
	else:
		print('NO')


from math import sqrt

def minimum(p1, p2, a1, a2):
	a = 0
	c = 0
	for i in range(3):
		a = a + (a2[i] - a1[i]) ** 2
	a = a / 2
	for i in range(3):
		c = c + (p2[i] - p1[i]) * (a2[i] - a1[i])
	if -4 * a * c > 0:
		t = sqrt(-4 * a * c)
		t = t / 2
		t = t / a
		return t
	else:
		return 0

def distance(p1, p2, a1, a2, t):
	d1 = 0
	d2 = 0
	total = 0
	for i in range(3):
		d1 = p1[i] + 0.5 * a1[i] * t ** 2
		d2 = p2[i] + 0.5 * a2[i] * t ** 2
		total = total + (d2 - d1) ** 2
	return sqrt(total)
T = int(input())
a1 = []
a2 = []
p1 = []
p2 = []
rad = []
for i in range(T):
	rad = str(input()).split(' ')
	p1 = str(input()).split(' ')
	a1 = str(input()).split(' ')
	p2 = str(input()).split(' ')
	a2 = str(input()).split(' ')
	a1 = [int(x) for x in a1]
	p1 = [int(x) for x in p1]
	a2 = [int(x) for x in a2]
	p2 = [int(x) for x in p2]
	time = minimum(p1, p2, a1, a2)
	dist = distance(p1, p2, a1, a2, time)
	if int(rad[0]) + int(rad[1]) < dist:
		print('NO')
	else:
		print('YES')


from math import sqrt

def CheckCollision(P1, A1, R1, P2, A2, R2):
	(x1, y1, z1) = P1
	(a1, a2, a3) = A1
	(x2, y2, z2) = P2
	(b1, b2, b3) = A2
	(r1, r2) = [R1, R2]
	a = a1 ** 2 - 2 * a1 * b1 + a2 ** 2 - 2 * a2 * b2 + a3 ** 2 - 2 * a3 * b3 + b1 ** 2 + b2 ** 2 + b3 ** 2
	b = 2 * a1 * x1 - 2 * a1 * x2 + 2 * a2 * y1 - 2 * a2 * y2 + 2 * a3 * z1 - 2 * a3 * z2 - 2 * b1 * x1 + 2 * b1 * x2 - 2 * b2 * y1 + 2 * b2 * y2 - 2 * b3 * z1 + 2 * b3 * z2
	c = -r1 ** 2 - 2 * r1 * r2 - r2 ** 2 + x1 ** 2 - 2 * x1 * x2 + x2 ** 2 + y1 ** 2 - 2 * y1 * y2 + y2 ** 2 + z1 ** 2 - 2 * z1 * z2 + z2 ** 2
	Mantissa = b * b - 4 * a * c
	if Mantissa < 0:
		return 'NO'
	t1 = (-b + sqrt(Mantissa)) / (2 * a)
	t2 = (-b - sqrt(Mantissa)) / (2 * a)
	if t1 < 0 and t2 < 0:
		return 'NO'
	return 'YES'
T = int(input())
while T:
	T = T - 1
	(R1, R2) = [int(i) for i in input().split()]
	P1 = [int(i) for i in input().split()]
	A1 = [int(i) for i in input().split()]
	P2 = [int(i) for i in input().split()]
	A2 = [int(i) for i in input().split()]
	print(CheckCollision(P1, A1, R1, P2, A2, R2))


import cmath
for i in range(int(input())):
	(R1, R2) = tuple(map(int, input().split()))
	(x1, y1, z1) = tuple(map(int, input().split()))
	(ax1, ay1, az1) = tuple(map(int, input().split()))
	(x2, y2, z2) = tuple(map(int, input().split()))
	(ax2, ay2, az2) = tuple(map(int, input().split()))
	dist = abs(cmath.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2))
	while True:
		(x1, y1, z1) = (x1 + ax1 / 100, y1 + ay1 / 100, z1 + az1 / 100)
		(x2, y2, z2) = (x2 + ax2 / 100, y2 + ay2 / 100, z2 + az2 / 100)
		next_dist = abs(cmath.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2))
		if next_dist > dist:
			print('NO')
			break
		elif next_dist < R1 + R2:
			print('YES')
			break


import math
for i in range(int(input())):
	(R1, R2) = [int(j) for j in input().split(' ')]
	(S1, a1, S2, a2) = [[int(j) for j in input().split(' ')] for i in range(4)]
	t = -2 * sum(((S1[i] - S2[i]) * (a1[i] - a2[i]) for i in range(3))) / sum(((a1[i] - a2[i]) ** 2 for i in range(3)))
	if t < 0:
		t = 0
	t = math.sqrt(t)
	if sum(((S1[i] + a1[i] * t ** 2 / 2 - S2[i] - a2[i] * t ** 2 / 2) ** 2 for i in range(3))) <= (R1 + R2) ** 2:
		print('YES')
		continue
	print('NO')


import math, sys
T = int(sys.stdin.readline())
mag = lambda p: math.sqrt(sum((x * x for x in p)))
dist = lambda p1, p2: mag((y - x for (x, y) in zip(p1, p2)))
for _ in range(T):
	(R1, R2) = list(map(int, sys.stdin.readline().split()))
	p1 = list(map(int, sys.stdin.readline().split()))
	a1 = list(map(int, sys.stdin.readline().split()))
	p2 = list(map(int, sys.stdin.readline().split()))
	a2 = list(map(int, sys.stdin.readline().split()))
	dp = [y - x for (x, y) in zip(p1, p2)]
	da = [y - x for (x, y) in zip(a1, a2)]
	t2 = -2.0 * sum((p * a for (p, a) in zip(dp, da))) / sum((a * a for a in da))
	if t2 >= 0:
		print('YES' if mag((p + a * t2 / 2 for (p, a) in zip(dp, da))) <= R1 + R2 else 'NO')
	else:
		print('NO')


import sys

def dotprod(u, v):
	prod = [a * b for (a, b) in zip(u, v)]
	return sum(prod)
source = sys.stdin
T = int(source.readline())
for _ in range(T):
	[r1, r2] = [int(s) for s in source.readline().split()]
	D = (r1 + r2) ** 2
	X1 = [int(s) for s in source.readline().split()]
	A1 = [int(s) for s in source.readline().split()]
	X2 = [int(s) for s in source.readline().split()]
	A2 = [int(s) for s in source.readline().split()]
	X = [b - a for (a, b) in zip(X1, X2)]
	A = [b - a for (a, b) in zip(A1, A2)]
	XX = dotprod(X, X)
	AA = dotprod(A, A)
	AX = dotprod(A, X)
	if AA == 0:
		print('NO')
	elif AX >= 0:
		print('NO')
	else:
		tSqrd = -2 * AX / AA
		closest = XX + tSqrd * AX + tSqrd * tSqrd * AA / 4
		if closest <= D:
			print('YES')
		else:
			print('NO')


def mod(L):
	return pow(L[0] * L[0] + L[1] * L[1] + L[2] * L[2], 0.5)
import math
t = int(input())
res = []
for i in range(t):
	(r1, r2) = [int(i) for i in input().split()]
	p1 = [int(i) for i in input().split()]
	a1 = [int(i) for i in input().split()]
	p2 = [int(i) for i in input().split()]
	a2 = [int(i) for i in input().split()]
	p = list(map(lambda x: x[1] - x[0], zip(p1, p2)))
	a = list(map(lambda x: x[1] - x[0], zip(a1, a2)))
	prod = sum([p[i] * a[i] for i in range(3)])
	if prod > 0:
		res.append('NO')
		continue
	dis = math.sin(math.acos(prod / (mod(p) * mod(a)))) * mod(p)
	if dis <= r1 + r2:
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


t = int(input())
for _ in range(t):
	(r1, r2) = map(int, input().split())
	p1 = map(int, input().split())
	a1 = map(int, input().split())
	p2 = map(int, input().split())
	a2 = map(int, input().split())
	dr = [x2 - x1 for (x1, x2) in zip(p1, p2)]
	da = [x2 - x1 for (x1, x2) in zip(a1, a2)]
	ra = sum((x * a for (x, a) in zip(dr, da)))
	if ra >= 0:
		print('NO')
	else:
		rsq = sum((x * x for x in dr))
		asq = sum((a * a for a in da))
		tsq = -2 * ra / asq
		dsq = rsq + tsq * ra + 0.25 * tsq * tsq * asq
		print('YES' if dsq <= (r1 + r2) ** 2 else 'NO')


from math import sqrt

def spheres(R1, R2, p1, a1, p2, a2):
	d_a = [a2[0] - a1[0], a2[1] - a1[1], a2[2] - a1[2]]
	d_p = [p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]]
	A = (d_a[0] ** 2 + d_a[1] ** 2 + d_a[2] ** 2) / 4
	B = d_a[0] * d_p[0] + d_a[1] * d_p[1] + d_a[2] * d_p[2]
	C = d_p[0] ** 2 + d_p[1] ** 2 + d_p[2] ** 2 - (R1 + R2) ** 2
	discrim = B ** 2 - 4 * A * C
	if discrim < 0:
		return False
	if A != 0:
		t2 = (-B + sqrt(discrim)) / (2 * A)
		return t2 >= 0
	if B != 0:
		t2 = -C / B
		return t2 >= 0
	return False
T = int(input())
for _ in range(T):
	(R1, R2) = [int(i) for i in input().split()]
	p1 = [int(i) for i in input().split()]
	a1 = [int(i) for i in input().split()]
	p2 = [int(i) for i in input().split()]
	a2 = [int(i) for i in input().split()]
	print('YES' if spheres(R1, R2, p1, a1, p2, a2) else 'NO')


import math, sys
T = int(sys.stdin.readline())
mag = lambda p: math.sqrt(sum((x * x for x in p)))
dist = lambda p1, p2: mag((y - x for (x, y) in zip(p1, p2)))
for _ in range(T):
	(R1, R2) = list(map(int, sys.stdin.readline().split()))
	p1 = list(map(int, sys.stdin.readline().split()))
	a1 = list(map(int, sys.stdin.readline().split()))
	p2 = list(map(int, sys.stdin.readline().split()))
	a2 = list(map(int, sys.stdin.readline().split()))
	dp = [y - x for (x, y) in zip(p1, p2)]
	da = [y - x for (x, y) in zip(a1, a2)]
	t2 = -2.0 * sum((p * a for (p, a) in zip(dp, da))) / sum((a * a for a in da))
	if t2 >= 0:
		print('YES' if mag((p + a * t2 / 2 for (p, a) in zip(dp, da))) <= R1 + R2 else 'NO')
	else:
		print('NO')


from math import log, exp
T = int(input())
for _ in range(T):
	(r1, r2) = [int(ns) for ns in str(input()).split()]
	(x1, y1, z1) = [int(ns) for ns in str(input()).split()]
	(ax1, ay1, az1) = [int(ns) for ns in str(input()).split()]
	(x2, y2, z2) = [int(ns) for ns in str(input()).split()]
	(ax2, ay2, az2) = [int(ns) for ns in str(input()).split()]
	D = (r1 + r2) ** 2
	xd = x1 - x2
	yd = y1 - y2
	zd = z1 - z2
	axd = ax1 - ax2
	ayd = ay1 - ay2
	azd = az1 - az2
	vdp = xd * axd + yd * ayd + zd * azd
	vdv = axd * axd + ayd * ayd + azd * azd
	t = -vdp / vdv
	if t < 0:
		t = 0
	c = (xd + t * axd) ** 2 + (yd + t * ayd) ** 2 + (zd + t * azd) ** 2
	if c <= D:
		print('YES')
	else:
		print('NO')


def distance_min(x1, y1, z1, x2, y2, z2, a1x, a1y, a1z, a2x, a2y, a2z):
	diff_ax = a2x - a1x
	diff_ay = a2y - a1y
	diff_az = a2z - a1z
	diff_x = x2 - x1
	diff_y = y2 - y1
	diff_z = z2 - z1
	A = diff_ax ** 2 + diff_ay ** 2 + diff_az ** 2
	A /= float(4)
	B = float(diff_ax * diff_x + diff_ay * diff_y + diff_az * diff_z)
	C = float(diff_x ** 2 + diff_y ** 2 + diff_z ** 2)
	if B >= 0:
		return C
	else:
		minimum = (4 * A * C - B ** 2) / (4.0 * A)
		return minimum

def main():
	t = int(input())
	for x in range(t):
		(r1, r2) = map(int, input().split())
		(x1, y1, z1) = map(int, input().split())
		(a1x, a1y, a1z) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		(a2x, a2y, a2z) = map(int, input().split())
		distance = distance_min(x1, y1, z1, x2, y2, z2, a1x, a1y, a1z, a2x, a2y, a2z)
		if distance < (r1 + r2) ** 2:
			print('YES')
		else:
			print('NO')
main()


import math, sys
T = int(sys.stdin.readline())
mag = lambda p: math.sqrt(sum((x * x for x in p)))
dist = lambda p1, p2: mag((y - x for (x, y) in zip(p1, p2)))
for _ in range(T):
	(R1, R2) = list(map(int, sys.stdin.readline().split()))
	p1 = list(map(int, sys.stdin.readline().split()))
	a1 = list(map(int, sys.stdin.readline().split()))
	p2 = list(map(int, sys.stdin.readline().split()))
	a2 = list(map(int, sys.stdin.readline().split()))
	dp = [y - x for (x, y) in zip(p1, p2)]
	da = [y - x for (x, y) in zip(a1, a2)]
	t2 = -2.0 * sum((p * a for (p, a) in zip(dp, da))) / sum((a * a for a in da))
	if t2 >= 0:
		print('YES' if mag((p + a * t2 / 2 for (p, a) in zip(dp, da))) <= R1 + R2 else 'NO')
	else:
		print('NO')


def parallel(a1, a2):
	for i in range(len(a1)):
		if a1[i] == 0 and a2[i] != 0 or (a1[i] != 0 and a2[i] == 0):
			return False
	for i in range(len(a1)):
		if a1[i] == 0:
			return parallel(a1[:i] + a1[i + 1:], a2[:i] + a2[i + 1:])
	return len(tuple(set(tuple([a1[i] / a2[i] for i in range(len(a1))])))) == 1 and tuple([a1[i] / a2[i] for i in range(len(a1))])[0] > 0

def antiparallel(a1, a2):
	for i in range(len(a1)):
		if a1[i] == 0 and a2[i] != 0 or (a1[i] != 0 and a2[i] == 0):
			return False
	for i in range(len(a1)):
		if a1[i] == 0:
			return antiparallel(a1[:i] + a1[i + 1:], a2[:i] + a2[i + 1:])
	return len(tuple(set(tuple([a1[i] / a2[i] for i in range(len(a1))])))) == 1 and tuple([a1[i] / a2[i] for i in range(len(a1))])[0] < 0

def subtract(v1, v2):
	return tuple([v1[i] - v2[i] for i in range(3)])

def normalize(vec):
	return [i / sum([j ** 2 for j in vec]) ** 0.5 for i in vec]

def cross_product(a, b):
	(a1, a2, a3) = a
	(b1, b2, b3) = b
	return (a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1)

def magnitude(vector):
	return sum([i ** 2 for i in vector]) ** 0.5

def collide(center1, radius1, a1, center2, radius2, a2):
	(x1, y1, z1) = center1
	(x2, y2, z2) = center2
	(a1i, a1j, a1k) = a1
	(a2i, a2j, a2k) = a2
	if parallel(a1, a2):
		v1 = normalize(a1)
		v2 = subtract(center2, center1)
		dist = magnitude(cross_product(v1, v2))
		if dist > radius1 + radius2:
			return False
		faster = max(a1, a2, key=lambda a: magnitude(a))
		slower = min(a1, a2, key=lambda a: magnitude(a))
		return not parallel(a1, subtract(faster, slower))
	if antiparallel(a1, a2):
		v1 = normalize(a1)
		v2 = subtract(center2, center1)
		dist = magnitude(cross_product(v1, v2))
		if dist > radius1 + radius2:
			return False
		return not parallel(a1, subtract(center1, center2))
	x = x2 - x1
	y = y2 - y1
	z = z2 - z1
	ai = a2i - a1i
	aj = a2j - a1j
	ak = a2k - a1k
	if ai * x + aj * y + ak * z > 0:
		return False
	t = (-2 * (ai * x + aj * y + ak * z) / (ai ** 2 + aj ** 2 + ak ** 2)) ** 0.5
	min_dist = ((x + 0.5 * t ** 2 * ai) ** 2 + (y + 0.5 * t ** 2 * aj) ** 2 + (z + 0.5 * t ** 2 * ak) ** 2) ** 0.5
	return min_dist <= radius1 + radius2
T = int(input())
for test in range(T):
	(radius1, radius2) = tuple([int(i) for i in input().split()])
	center1 = tuple([int(i) for i in input().split()])
	a1 = tuple([int(i) for i in input().split()])
	center2 = tuple([int(i) for i in input().split()])
	a2 = tuple([int(i) for i in input().split()])
	print('YES' if collide(center1, radius1, a1, center2, radius2, a2) else 'NO')


import math, sys
T = int(sys.stdin.readline())
mag = lambda p: math.sqrt(sum((x * x for x in p)))
dist = lambda p1, p2: mag((y - x for (x, y) in zip(p1, p2)))
for _ in range(T):
	(R1, R2) = list(map(int, sys.stdin.readline().split()))
	p1 = list(map(int, sys.stdin.readline().split()))
	a1 = list(map(int, sys.stdin.readline().split()))
	p2 = list(map(int, sys.stdin.readline().split()))
	a2 = list(map(int, sys.stdin.readline().split()))
	dp = [y - x for (x, y) in zip(p1, p2)]
	da = [y - x for (x, y) in zip(a1, a2)]
	t2 = -2.0 * sum((p * a for (p, a) in zip(dp, da))) / sum((a * a for a in da))
	if t2 >= 0:
		print('YES' if mag((p + a * t2 / 2 for (p, a) in zip(dp, da))) <= R1 + R2 else 'NO')
	else:
		print('NO')


def dist(p1, p2):
	return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 + (p1[2] - p2[2]) ** 2) ** 0.5

def dist_at_time(t):
	c1 = [p1[0] + a1[0] * t, p1[1] + a1[1] * t, p1[2] + a1[2] * t]
	c2 = [p2[0] + a2[0] * t, p2[1] + a2[1] * t, p2[2] + a2[2] * t]
	return dist(c1, c2)
for i in range(int(input())):
	[r1, r2] = list(map(int, input().split()))
	p1 = list(map(int, input().split()))
	a1 = list(map(int, input().split()))
	p2 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	if dist_at_time(0) < r1 + r2:
		print('YES1')
		continue
	if dist_at_time(0.001) > dist_at_time(0):
		print('NO')
		continue
	t = 1
	best = dist_at_time(0)
	bestt = 0
	found = False
	for t in range(1, 201):
		if dist_at_time(t) < best:
			if dist_at_time(t) < r1 + r2:
				found = True
				break
			best = dist_at_time(t)
			bestt = t
	if found:
		print('YES')
	else:
		d = int(2 * abs(dist_at_time(bestt) - dist_at_time(bestt + 1))) + 5
		for i in range((bestt - 1) * d, (bestt + 1) * d):
			t = i / d
			if dist_at_time(t) < best:
				if dist_at_time(t) < r1 + r2:
					found = True
					break
				best = dist_at_time(t)
				bestt = t
		if found:
			print('YES')
		else:
			print('NO')


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(r1, r2) = map(int, sys.stdin.readline().split(' '))
	(x1, y1, z1) = map(int, sys.stdin.readline().split(' '))
	(a1, b1, c1) = map(int, sys.stdin.readline().split(' '))
	(x2, y2, z2) = map(int, sys.stdin.readline().split(' '))
	(a2, b2, c2) = map(int, sys.stdin.readline().split(' '))
	(x, y, z) = (x2 - x1, y2 - y1, z2 - z1)
	(a, b, c) = (a2 - a1, b2 - b1, c2 - c1)
	r = r1 + r2
	cross = (x * b - y * a) ** 2 + (y * c - z * b) ** 2 + (z * a - x * c) ** 2
	rs = r ** 2 * (a ** 2 + b ** 2 + c ** 2)
	dot = x * a + y * b + z * c
	if cross > rs:
		print('NO')
	elif dot < 0:
		print('YES')
	else:
		print('NO')


from math import sqrt
for _ in range(int(input())):
	(r1, r2) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	(a1x, a1y, a1z) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	(a2x, a2y, a2z) = map(int, input().split())
	x = x2 - x1
	y = y2 - y1
	z = z2 - z1
	ax = a2x - a1x
	ay = a2y - a1y
	az = a2z - a1z
	a = ax ** 2 + ay ** 2 + az ** 2
	b = 2 * (ax * x + ay * y + az * z)
	c = x ** 2 + y ** 2 + z ** 2 - (r1 + r2) ** 2
	print('YES' if b ** 2 >= 4 * a * c and sqrt(b ** 2 - 4 * a * c) >= b else 'NO')


import sys
import math
T = int(input())
for i in range(0, T):
	r = input(str()).strip().split(' ')
	R1 = float(r[0])
	R2 = float(r[1])
	c1 = input(str()).strip().split(' ')
	x1 = float(c1[0])
	y1 = float(c1[1])
	z1 = float(c1[2])
	a1 = input(str()).strip().split(' ')
	c2 = input(str()).strip().split(' ')
	x2 = float(c2[0])
	y2 = float(c2[1])
	z2 = float(c2[2])
	a2 = input(str()).strip().split(' ')
	if math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2) - R1 - R2 <= 0:
		print('YES')
		continue
	ax1 = float(a1[0])
	ay1 = float(a1[1])
	az1 = float(a1[2])
	ax2 = float(a2[0])
	ay2 = float(a2[1])
	az2 = float(a2[2])
	if ax1 == ax2 and ay1 == ay2 and (az1 == az2):
		print('NO')
		continue
	if (x1 - x2) * (ax1 - ax2) + (y1 - y2) * (ay1 - ay2) + (z1 - z2) * (az1 - az2) >= 0:
		print('NO')
		continue
	t = math.sqrt(((x1 - x2) * (ax1 - ax2) + (y1 - y2) * (ay1 - ay2) + (z1 - z2) * (az1 - az2)) / (-0.5 * (ax1 - ax2) ** 2 - 0.5 * (ay1 - ay2) ** 2 - 0.5 * (az1 - az2) ** 2))
	x1 = x1 + 0.5 * ax1 * t ** 2
	y1 = y1 + 0.5 * ay1 * t ** 2
	z1 = z1 + 0.5 * az1 * t ** 2
	x2 = x2 + 0.5 * ax2 * t ** 2
	y2 = y2 + 0.5 * ay2 * t ** 2
	z2 = z2 + 0.5 * az2 * t ** 2
	if math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2) - R1 - R2 <= 0:
		print('YES')
	else:
		print('NO')


def read_vec():
	line = input().split()
	return [int(line[0]), int(line[1]), int(line[2])]

def vec_diff(a, b):
	return [a[0] - b[0], a[1] - b[1], a[2] - b[2]]

def vec_dot(a, b):
	return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
T = int(input())
for case in range(T):
	line = input().split()
	R1 = int(line[0])
	R2 = int(line[1])
	p1 = read_vec()
	a1 = read_vec()
	p2 = read_vec()
	a2 = read_vec()
	x = vec_diff(p1, p2)
	v = vec_diff(a1, a2)
	a = vec_dot(x, v)
	res = 0
	if a < 0:
		b = vec_dot(v, v)
		d = (b * x[0] - a * v[0]) ** 2 + (b * x[1] - a * v[1]) ** 2 + (b * x[2] - a * v[2]) ** 2
		if d <= b * b * (R1 + R2) ** 2:
			res = 1
	if res:
		print('YES')
	else:
		print('NO')


import sys
tc_len = int(sys.stdin.readline())
for tc in range(tc_len):
	(r1, r2) = tuple((int(x) for x in sys.stdin.readline().split()))
	p1 = tuple((int(x) for x in sys.stdin.readline().split()))
	v1 = tuple((int(x) for x in sys.stdin.readline().split()))
	p2 = tuple((int(x) for x in sys.stdin.readline().split()))
	v2 = tuple((int(x) for x in sys.stdin.readline().split()))
	a = sum([(v1[i] - v2[i]) * (v1[i] - v2[i]) for i in range(3)])
	b = 2 * sum([(v1[i] - v2[i]) * (p1[i] - p2[i]) for i in range(3)])
	c = sum([(p1[i] - p2[i]) * (p1[i] - p2[i]) for i in range(3)])
	if a > 0 and -b / (2 * a) > 0 and (c - b * b / (4 * a) <= (r1 + r2) * (r1 + r2)):
		print('YES')
	else:
		print('NO')


import math

def read_ints():
	return [int(x) for x in input().strip().split(' ')]

def read_int():
	return int(input().strip())

def distance_travelled(t, a, b, c):
	return a * t ** 2 / 2 + b * t + c
T = read_int()
for t in range(T):
	(R1, R2) = read_ints()
	(x1, y1, z1) = read_ints()
	(a1i, a1j, a1k) = read_ints()
	(x2, y2, z2) = read_ints()
	(a2i, a2j, a2k) = read_ints()
	a = ((a1i - a2i) * (a1i - a2i) + (a1j - a2j) * (a1j - a2j) + (a1k - a2k) * (a1k - a2k)) / 2
	b = (x1 - x2) * (a1i - a2i) + (y1 - y2) * (a1j - a2j) + (z1 - z2) * (a1k - a2k)
	c = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)
	time = -b / a
	if time >= 0:
		D = distance_travelled(time, a, b, c)
	else:
		D = distance_travelled(0, a, b, c)
	if math.sqrt(D) <= R1 + R2:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(R1, R2) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	(ax1, ay1, az1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	(ax2, ay2, az2) = map(int, input().split())
	R = R1 + R2
	(x, y, z) = (x2 - x1, y2 - y1, z2 - z1)
	(ax, ay, az) = (ax2 - ax1, ay2 - ay1, az2 - az1)
	d = x * x + y * y + z * z
	if d <= R * R:
		print('YES')
	else:
		p = x * ax + y * ay + z * az
		if p >= 0:
			print('NO')
		else:
			d_ = d - (x * ax + y * ay + z * az) ** 2 / (ax * ax + ay * ay + az * az)
			if d_ > R * R:
				print('NO')
			else:
				print('YES')


res = []
for _ in range(int(input())):
	(r, x1, a1, x2, a2) = (tuple(map(int, input().split())) for _ in range(5))
	a = sum(((a1[i] - a2[i]) ** 2 for i in range(3)))
	b = 2 * sum(((a1[i] - a2[i]) * (x1[i] - x2[i]) for i in range(3)))
	c = sum(((x1[i] - x2[i]) ** 2 for i in range(3))) - sum(r) ** 2
	delta = b * b - 4 * a * c
	res.append('YES' if delta >= 0 and delta ** 0.5 > b else 'NO')
print(*res, sep='\n')


T = int(input())
cases = []
for i in range(T):
	(R1, R2) = [int(s) for s in input().split()]
	r1 = [int(s) for s in input().split()]
	a1 = [int(s) for s in input().split()]
	r2 = [int(s) for s in input().split()]
	a2 = [int(s) for s in input().split()]
	cases.append((R1, R2, r1, a1, r2, a2))
for (R1, R2, r1, a1, r2, a2) in cases:
	R = R1 + R2
	Dr = [x1 - x2 for (x1, x2) in zip(r1, r2)]
	Da = [ax1 - ax2 for (ax1, ax2) in zip(a1, a2)]
	DrDa = sum((x * ax for (x, ax) in zip(Dr, Da)))
	Dr2 = sum((x ** 2 for x in Dr))
	Da2 = sum((ax ** 2 for ax in Da))
	det = DrDa ** 2 - Da2 * (Dr2 - R ** 2)
	if det < 0 or DrDa > 0:
		print('NO')
	else:
		print('YES')


def vsum(x, y, a, b):
	return [a * i + b * j for (i, j) in zip(x, y)]

def dotprod(x, y):
	return sum((i * j for (i, j) in zip(x, y)))

def norm(x):
	return dotprod(x, x) ** 0.5
for _ in range(int(input())):
	(r1, r2) = [int(a) for a in input().split()]
	p1 = [int(a) for a in input().split()]
	a1 = [int(a) for a in input().split()]
	p2 = [int(a) for a in input().split()]
	a2 = [int(a) for a in input().split()]
	(p, a) = (vsum(p1, p2, 1, -1), vsum(a1, a2, 1, -1))
	n = norm(a)
	if n == 0:
		print('NO')
		break
	t = -2 * dotprod(a, p) / n ** 2
	if t < 0:
		print('NO')
	else:
		d1 = norm(p)
		d2 = norm(vsum(a, p, t / 2, 1))
		if d2 >= d1 or d2 > r1 + r2:
			print('NO')
		else:
			print('YES')


ctest = int(input())
for itest in range(ctest):
	tokens = input().split()
	R1 = int(tokens[0])
	R2 = int(tokens[1])
	tokens = input().split()
	x1 = int(tokens[0])
	y1 = int(tokens[1])
	z1 = int(tokens[2])
	tokens = input().split()
	a1x = int(tokens[0])
	a1y = int(tokens[1])
	a1z = int(tokens[2])
	tokens = input().split()
	x2 = int(tokens[0])
	y2 = int(tokens[1])
	z2 = int(tokens[2])
	tokens = input().split()
	a2x = int(tokens[0])
	a2y = int(tokens[1])
	a2z = int(tokens[2])
	num = -2 * ((x1 - x2) * (a1x - a2x) + (y1 - y2) * (a1y - a2y) + (z1 - z2) * (a1z - a2z))
	if num < 0:
		print('NO')
	else:
		den = (a1x - a2x) ** 2 + (a1y - a2y) ** 2 + (a1z - a2z) ** 2
		tsq = num / den
		dx = x1 + 0.5 * a1x * tsq - (x2 + 0.5 * a2x * tsq)
		dy = y1 + 0.5 * a1y * tsq - (y2 + 0.5 * a2y * tsq)
		dz = z1 + 0.5 * a1z * tsq - (z2 + 0.5 * a2z * tsq)
		dsq = dx ** 2 + dy ** 2 + dz ** 2
		if dsq <= (R1 + R2) ** 2:
			print('YES')
		else:
			print('NO')


import math

def list_diff(lst1, lst2):
	diff = [l - r for (l, r) in zip(lst1, lst2)]
	return diff

def list_scale(lst, s):
	return [elem * s for elem in lst]

def list_norm2(lst):
	return sum([elem ** 2 for elem in lst])

def list_dot(lst1, lst2):
	return sum([l * r for (l, r) in zip(lst1, lst2)])

def root_p(a, b, c):
	crit = b ** 2 - 4 * a * c
	if crit < 0:
		return -1
	else:
		numerator_p = -b + math.sqrt(crit)
		denom = 2 * a
		return numerator_p / denom
T = int(input())
for _ in range(T):
	(r1, r2) = map(int, input().split())
	p1 = map(float, input().split())
	a1 = map(float, input().split())
	p2 = map(float, input().split())
	a2 = map(float, input().split())
	a_diff = list_diff(a1, a2)
	p_diff = list_diff(p1, p2)
	r = (r1 + r2) ** 2
	c = list_norm2(p_diff) - r
	b = list_dot(a_diff, p_diff)
	a = list_norm2(list_scale(a_diff, 1 / 2))
	tp = root_p(a, b, c)
	if tp >= 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(r1, r2) = map(int, input().split())
	x1 = list(map(int, input().split()))
	a1 = list(map(int, input().split()))
	x2 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))

	def sqofra(u, v):
		return (u[0] - v[0]) ** 2 + (u[1] - v[1]) ** 2 + (u[2] - v[2]) ** 2

	def ra(a1, a2, r1, r2):
		return (r2[0] - r1[0]) * (a2[0] - a1[0]) + (r2[1] - r1[1]) * (a2[1] - a1[1]) + (r2[2] - r1[2]) * (a2[2] - a1[2])
	a = sqofra(a2, a1) / 4
	b = ra(a1, a2, x1, x2)
	c = sqofra(x2, x1) - (r1 + r2) ** 2
	D = b ** 2 - 4 * a * c
	if a == 0:
		if b == 0:
			if c <= 0:
				print('YES')
			else:
				print('NO')
		elif -c / b >= 0:
			print('YES')
		else:
			print('NO')
	else:
		from math import sqrt as sqrt
		if D < 0:
			if a < 0:
				print('YES')
			else:
				print('NO')
		else:
			p1 = (-b + sqrt(D)) / 2 / a
			p2 = (-b - sqrt(D)) / 2 / a
			if p1 >= 0 or p2 >= 0:
				print('YES')
			else:
				print('NO')


N = int(input().strip())
for _ in range(N):
	(R1, R2) = list(map(int, input().strip().split(' ')))
	X1 = list(map(int, input().strip().split(' ')))
	A1 = list(map(int, input().strip().split(' ')))
	X2 = list(map(int, input().strip().split(' ')))
	A2 = list(map(int, input().strip().split(' ')))
	A = (A1[0] - A2[0], A1[1] - A2[1], A1[2] - A2[2])
	X = (X1[0] - X2[0], X1[1] - X2[1], X1[2] - X2[2])
	LX = X[0] ** 2 + X[1] ** 2 + X[2] ** 2
	LA = A[0] ** 2 + A[1] ** 2 + A[2] ** 2
	inter = False
	if LX < (R1 + R2) ** 2:
		inter = True
	elif LA != 0:
		XdotA = X[0] * A[0] + X[1] * A[1] + X[2] * A[2]
		T = -XdotA / LA
		if T > 0.0:
			inter = LX + LA * T ** 2 + 2.0 * XdotA * T < (R1 + R2) ** 2
	if inter:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	(R1, R2) = [int(R) for R in input().split()]
	pos1 = [int(pos) for pos in input().split()]
	acc1 = [int(acc) for acc in input().split()]
	pos2 = [int(pos) for pos in input().split()]
	acc2 = [int(acc) for acc in input().split()]
	da = [a1 - a2 for (a1, a2) in zip(acc1, acc2)]
	dp = [p1 - p2 for (p1, p2) in zip(pos1, pos2)]
	a2 = sum([a ** 2 for a in da])
	p2 = sum([p ** 2 for p in dp])
	ap = sum([a * p for (a, p) in zip(da, dp)])
	if p2 <= (R1 + R2) ** 2:
		print('YES')
		continue
	a = a2
	b = 2 * ap
	c = p2 - (R1 + R2) ** 2
	if (b ** 2 - 4 * a * c >= 0) & (-b / 2 / a >= 0):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	r = input().split()
	p1 = input().split()
	a1 = input().split()
	p2 = input().split()
	a2 = input().split()
	r1 = int(r[0])
	r2 = int(r[1])
	x1 = int(p1[0])
	y1 = int(p1[1])
	z1 = int(p1[2])
	a1x = int(a1[0])
	a1y = int(a1[1])
	a1z = int(a1[2])
	x2 = int(p2[0])
	y2 = int(p2[1])
	z2 = int(p2[2])
	a2x = int(a2[0])
	a2y = int(a2[1])
	a2z = int(a2[2])
	delta_a_square = (a2x - a1x) ** 2 + (a2y - a1y) ** 2 + (a2z - a1z) ** 2
	delta_p_square = (x2 - x1) ** 2 + (y2 - y1) ** 2 + (z2 - z1) ** 2
	delta_p_delta_a = (x2 - x1) * (a2x - a1x) + (y2 - y1) * (a2y - a1y) + (z2 - z1) * (a2z - a1z)
	term_in_disc = delta_a_square * (delta_p_square - (r1 + r2) ** 2)
	if delta_a_square == 0:
		if delta_p_square == (r1 + r2) ** 2:
			print('YES')
		else:
			print('NO')
	elif delta_p_delta_a ** 2 < term_in_disc:
		print('NO')
	elif delta_p_delta_a <= 0:
		print('YES')
	elif term_in_disc <= 0:
		print('YES')
	else:
		print('NO')


import operator
t = int(input())
for z in range(t):
	(r1, r2) = [int(i) for i in input().strip().split(' ')]
	p = [int(i) for i in input().strip().split(' ')]
	a = [int(i) for i in input().strip().split(' ')]
	p = list(map(operator.sub, [int(i) for i in input().strip().split(' ')], p))
	a = list(map(operator.sub, [int(i) for i in input().strip().split(' ')], a))
	temp = sum(list(map(operator.mul, p, a))) / sum([i * i for i in a])
	if temp < 0:
		dist = list(map(operator.sub, p, [temp * i for i in a]))
		dist = sum([i * i for i in dist])
	else:
		dist = sum([i * i for i in p])
	if (r1 + r2) ** 2 >= dist:
		print('YES')
	else:
		print('NO')


T = int(input())

def distance(x):
	d = x[0] ** 2 + x[1] ** 2 + x[2] ** 2
	return d

def difference(a, b):
	s = 0
	for i in range(3):
		s += a[i] * b[i]
	return s

def test(s, a, r):
	d0 = distance(s)
	if d0 <= r ** 2:
		return 'YES'
	c = d0 - r ** 2
	b = difference(a, s)
	a = distance(a) / 4
	try:
		t1 = (b ** 2 - 4 * a * c) ** 0.5 - b
		t2 = -(b ** 2 - 4 * a * c) ** 0.5 - b
		if t1 > 0 or t2 > 0:
			return 'YES'
		else:
			return 'NO'
	except:
		return 'NO'
for i in range(T):
	s1 = []
	a1 = []
	s2 = []
	a2 = []
	l = input().split()
	r = int(l[0]) + int(l[1])
	s1 = list(input().split())
	a1 = list(input().split())
	s2 = list(input().split())
	a2 = list(input().split())
	for i in range(3):
		s1[i] = int(s1[i]) - int(s2[i])
		a1[i] = int(a1[i]) - int(a2[i])
	print(test(s1, a1, r))


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import math
T = int(input())
for i in range(T):
	[R1, R2] = [int(x) for x in input().split(' ')]
	p1 = [int(x) for x in input().split(' ')]
	a1 = [int(x) for x in input().split(' ')]
	p2 = [int(x) for x in input().split(' ')]
	a2 = [int(x) for x in input().split(' ')]
	D2 = (R1 + R2) * (R1 + R2)
	da = [x - y for (x, y) in zip(a1, a2)]
	dp = [x - y for (x, y) in zip(p1, p2)]
	c2 = sum([x * x for x in da])
	c1 = 2 * sum([x * y for (x, y) in zip(da, dp)])
	c0 = sum([x * x for x in dp]) - D2
	discr = c1 * c1 - 4 * c0 * c2
	if discr > 0:
		t_1 = (-c1 + math.sqrt(discr)) / (2 * c2)
		t_2 = (-c1 - math.sqrt(discr)) / (2 * c2)
		if c2 < 0:
			res = True
		else:
			res = t_1 >= 0 or t_2 >= 0
	else:
		res = c2 < 0
	print('YES' if res else 'NO')


t = int(input())
for ti in range(t):
	d = sum([int(x) for x in input().strip().split()])
	pos1 = [int(x) for x in input().strip().split()]
	acc1 = [int(x) for x in input().strip().split()]
	pos2 = [int(x) for x in input().strip().split()]
	acc2 = [int(x) for x in input().strip().split()]
	diff_pos = [a - b for (a, b) in zip(pos1, pos2)]
	diff_acc = [a - b for (a, b) in zip(acc1, acc2)]
	a = sum([x ** 2 for x in diff_acc])
	b = sum([x * y for (x, y) in zip(diff_acc, diff_pos)])
	c = sum([x ** 2 for x in diff_pos]) - d * d
	if c <= 0:
		print('YES')
		continue
	if a == 0:
		print('NO')
		continue
	if b * b >= a * c:
		print('YES' if b <= 0 else 'NO')
	else:
		print('NO')


def contact(r1, x1, a1, r2, x2, a2):
	x = [z[1] - z[0] for z in zip(x1, x2)]
	a = [z[1] - z[0] for z in zip(a1, a2)]
	r = r1 + r2
	x_2 = x[0] ** 2 + x[1] ** 2 + x[2] ** 2
	a_2 = a[0] ** 2 + a[1] ** 2 + a[2] ** 2
	ax = a[0] * x[0] + a[1] * x[1] + a[2] * x[2]
	if x_2 <= r ** 2:
		return 'YES'
	if ax > 0:
		return 'NO'
	if x_2 - ax ** 2 / a_2 <= r ** 2:
		return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	(r1, r2) = (int(x) for x in input().strip().split(' '))
	x1 = [int(x) for x in input().strip().split(' ')]
	a1 = [int(x) for x in input().strip().split(' ')]
	x2 = [int(x) for x in input().strip().split(' ')]
	a2 = [int(x) for x in input().strip().split(' ')]
	print(contact(r1, x1, a1, r2, x2, a2))


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import sys

def diff(x, y):
	return [x[i] - y[i] for i in range(3)]

def dot(x, y):
	return sum([x[i] * y[i] for i in range(3)])

def will_contact(r1, r2, p1, a1, p2, a2):
	p = diff(p1, p2)
	a = diff(a1, a2)
	r = r1 + r2
	t = max(-dot(a, p) / dot(a, a), 0)
	p = [p[i] + a[i] * t for i in range(3)]
	d_squared = dot(p, p)
	return d_squared <= r ** 2
n_cases = int(sys.stdin.readline().strip())
cases = [[] for n in range(n_cases)]
for i in range(n_cases):
	cases[i].extend([int(x) for x in sys.stdin.readline().split()])
	for j in range(4):
		cases[i].append([int(x) for x in sys.stdin.readline().strip().split()])
for case in cases:
	if will_contact(*case):
		print('YES')
	else:
		print('NO')


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import math

def compute_distance(x1, x2):
	return math.sqrt(sum([(i - j) ** 2 for (i, j) in zip(x1, x2)]))

def evolve_system(x1, x2, a1, a2, dt):
	x1_ev = [i + j * dt for (i, j) in zip(x1, a1)]
	x2_ev = [i + j * dt for (i, j) in zip(x2, a2)]
	return (x1_ev, x2_ev)

def calc_contact(r1, r2, x1, a1, x2, a2):
	step = 0.001
	t = 0
	dist = compute_distance(x1, x2)
	while t < 10 ** 4:
		new_dist = compute_distance(x1, x2)
		if new_dist < r1 + r2:
			return True
		elif new_dist > dist:
			return False
		else:
			dist = new_dist
			(x1, x2) = evolve_system(x1, x2, a1, a2, step)
			t += step
	return False
num_inputs = int(input())
for i in range(num_inputs):
	radii = input()
	(r1, r2) = [float(i) for i in radii.split(' ')]
	x1 = [float(i) for i in input().split(' ')]
	a1 = [float(i) for i in input().split(' ')]
	x2 = [float(i) for i in input().split(' ')]
	a2 = [float(i) for i in input().split(' ')]
	if calc_contact(r1, r2, x1, a1, x2, a2):
		print('YES')
	else:
		print('NO')


import sys
import math

def read_one():
	return int(input().strip())

def read_two():
	(x, y) = input().strip().split(' ')
	return [int(x), int(y)]

def read_three():
	(x, y, z) = input().strip().split(' ')
	return [int(x), int(y), int(z)]

def sub(p, q):
	return [p[0] - q[0], p[1] - q[1], p[2] - q[2]]

def vec(a, b):
	return sub(b, a)

def dot(u, v):
	return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]

def normalize(u):
	m2 = dot(u, u)
	if m2 == 0:
		return u
	import math
	n = math.sqrt(m2)
	return [u[0] / n, u[1] / n, u[2] / n]

def execute(r1, p1, a1, r2, p2, a2):
	AB = vec(p1, p2)
	ba = sub(a2, a1)
	baba = dot(ba, ba)
	if baba == 0:
		return 'NO'
	t = -2 * dot(ba, vec(p1, p2)) / baba
	if t < 0:
		return 'NO'
	pt = [p1[i] + 0.5 * t * t * a1[i] for i in range(3)]
	qt = [p2[i] + 0.5 * t * t * a2[i] for i in range(3)]
	d2 = 0.25 * baba * t * t + dot(ba, AB) * t + dot(AB, AB)
	l = r1 + r2
	if d2 <= l * l:
		return 'YES'
	return 'NO'
t = read_one()
for _ in range(t):
	(r1, r2) = read_two()
	p1 = read_three()
	a1 = read_three()
	p2 = read_three()
	a2 = read_three()
	r = execute(r1, p1, a1, r2, p2, a2)
	print(r)


def dot(u, v):
	return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]

def min_dist_sqr(r1, a1, r2, a2):
	dr = (r1[0] - r2[0], r1[1] - r2[1], r1[2] - r2[2])
	da = (a1[0] - a2[0], a1[1] - a2[1], a1[2] - a2[2])
	a = dot(da, da)
	b = 2 * dot(dr, da)
	c = dot(dr, dr)
	if b >= 0:
		return c
	return c - b ** 2 / (4.0 * a)
T = int(input())
for t in range(T):
	(R1, R2) = map(int, input().split())
	r1 = tuple(map(int, input().split()))
	a1 = tuple(map(int, input().split()))
	r2 = tuple(map(int, input().split()))
	a2 = tuple(map(int, input().split()))
	if min_dist_sqr(r1, a1, r2, a2) <= (R1 + R2) ** 2:
		print('YES')
	else:
		print('NO')


T = int(input())

def D2(t, x, a, y, b):
	return sum(((x[i] + 0.5 * a[i] * t - (y[i] + 0.5 * b[i] * t)) ** 2 for i in range(3)))
for t0 in range(T):
	(R1, R2) = (int(n) for n in input().split())
	x = [int(n) for n in input().split()]
	a = [int(n) for n in input().split()]
	y = [int(n) for n in input().split()]
	b = [int(n) for n in input().split()]
	R = (R1 + R2) ** 2
	D = D2(0, x, a, y, b)
	if D < R:
		res = 'YES'
	else:
		den = sum((a[i] ** 2 - 2 * a[i] * b[i] + b[i] ** 2 for i in range(3)))
		if den == 0:
			print('€', end='')
			res = 'NO'
		else:
			t = abs(sum((2 * (y[i] * a[i] + x[i] * b[i] - x[i] * a[i] - y[i] * b[i]) for i in range(3))) / den)
			D = D2(t, x, a, y, b)
			if D < R:
				res = 'YES'
			else:
				res = 'NO'
	print(res)


import math, sys
T = int(sys.stdin.readline())
mag = lambda p: math.sqrt(sum((x * x for x in p)))
dist = lambda p1, p2: mag((y - x for (x, y) in zip(p1, p2)))
for _ in range(T):
	(R1, R2) = list(map(int, sys.stdin.readline().split()))
	p1 = list(map(int, sys.stdin.readline().split()))
	a1 = list(map(int, sys.stdin.readline().split()))
	p2 = list(map(int, sys.stdin.readline().split()))
	a2 = list(map(int, sys.stdin.readline().split()))
	dp = [y - x for (x, y) in zip(p1, p2)]
	da = [y - x for (x, y) in zip(a1, a2)]
	t2 = -2.0 * sum((p * a for (p, a) in zip(dp, da))) / sum((a * a for a in da))
	if t2 >= 0:
		print('YES' if mag((p + a * t2 / 2 for (p, a) in zip(dp, da))) <= R1 + R2 else 'NO')
	else:
		print('NO')


test_cases = int(input())

def dist(x, y, a, b, t):
	d = 0
	for i in range(0, 3):
		d += (x[i] - y[i] + (a[i] - b[i]) * t) * (x[i] - y[i] + (a[i] - b[i]) * t)
	return pow(d, 0.5)
for tc in range(0, test_cases):
	(r_1, r_2) = [int(a) for a in input().split()]
	x = [int(a) for a in input().split()]
	a = [int(a) for a in input().split()]
	y = [int(a) for a in input().split()]
	b = [int(a) for a in input().split()]
	top = 0
	bot = 0
	for i in range(0, 3):
		top += (x[i] - y[i]) * (a[i] - b[i])
		bot += (a[i] - b[i]) * (a[i] - b[i])
	if bot != 0:
		t = max(0, -1 * top / bot)
	else:
		t = 0
	if dist(x, y, a, b, t) <= r_1 + r_2:
		print('YES')
	else:
		print('NO')


import math

def test(R1, R2, p1, a1, p2, a2):
	t = -(2.0 * (p1[0] - p2[0]) * (a1[0] - a2[0]) + 2 * (p1[1] - p2[1]) * (a1[1] - a2[1]) + 2 * (p1[2] - p2[2]) * (a1[2] - a2[2])) / ((a1[0] - a2[0]) ** 2 + (a1[1] - a2[1]) ** 2 + (a1[2] - a2[2]) ** 2)
	t /= 2
	t = max(0, t)
	t = min(10000, t)
	dist = (p1[0] - p2[0] + (a1[0] - a2[0]) * t) ** 2 + (p1[1] - p2[1] + (a1[1] - a2[1]) * t) ** 2 + (p1[2] - p2[2] + (a1[2] - a2[2]) * t) ** 2
	if math.sqrt(dist) <= R1 + R2:
		return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	(R1a, R2a) = [float(i) for i in input().split()]
	p1a = [float(i) for i in input().split()]
	a1a = [float(i) for i in input().split()]
	p2a = [float(i) for i in input().split()]
	a2a = [float(i) for i in input().split()]
	print(test(R1a, R2a, p1a, a1a, p2a, a2a))


import math

class Vector(object):

	def __init__(self, coords):
		self.dim = len(coords)
		self.coords = list(map(int, coords))

	@property
	def norm2(self):
		ret = 0
		for i in range(self.dim):
			ret += self.coords[i] ** 2
		return ret

	def dot(self, rhs):
		ret = 0.0
		for i in range(self.dim):
			ret += self.coords[i] * rhs.coords[i]
		return ret

	def __sub__(self, rhs):
		coords = [self.coords[i] - rhs.coords[i] for i in range(self.dim)]
		return Vector(coords)

def main():
	N = int(input())
	for idx in range(N):
		radii = list(map(int, input().split()))
		lines = [list(map(int, input().split())) for _ in range(4)]
		positions = [Vector(lines[2 * i]) for i in range(2)]
		accelerations = [Vector(lines[2 * i + 1]) for i in range(2)]
		delta_x = positions[0] - positions[1]
		delta_a = accelerations[0] - accelerations[1]
		alpha = delta_a.norm2 / 4
		beta = delta_a.dot(delta_x)
		gamma = delta_x.norm2
		R = sum(radii)
		beta2 = beta * beta
		D2 = beta2 - 4 * alpha * (gamma - R * R)
		flag = D2 >= 0 and (beta <= 0 or D2 >= beta2)
		print('YES' if flag else 'NO')
main()


import sys

def get_p(p, a, t):
	return tuple((p[i] + a[i] * t * t / 2 for i in range(len(p))))

def dist2(p, q):
	return sum((pow(p[i] - q[i], 2) for i in range(len(p))))

def ternary_search(p1, a1, p2, a2):
	precision = 0.001
	(l, r) = (0, pow(3, 10))
	f = lambda t: dist2(get_p(p1, a1, t), get_p(p2, a2, t))
	(dl, dr) = (f(l), f(r))
	while r - l > precision:
		k = (r - l) / 3
		(m1, m2) = (l + k, l + 2 * k)
		(dm1, dm2) = (f(m1), f(m2))
		if dl > dm1 and dm1 > dm2 and (dm2 > dr):
			(l, dl) = (m1, dm1)
		elif dl < dm1 and dm1 < dm2 and (dm2 < dr):
			(r, dr) = (m2, dm2)
		elif dl > dm1 and dm1 < dm2:
			(r, dr) = (m2, dm2)
		elif dm1 > dm2 and dm2 < dr:
			(l, dl) = (m1, dm1)
		else:
			raise Exception('bad clause')
	print('l=%s r=%s' % (l, r), file=sys.stderr)
	return (dl + dr) / 2

def solve(c1, r1, a1, c2, r2, a2):
	print('c1=%s r1=%d a1=%s c2=%s r2=%d a2=%s' % (c1, r1, a1, c2, r2, a2), file=sys.stderr)
	d2 = ternary_search(c1, a1, c2, a2)
	r2 = pow(r1 + r2, 2)
	print('d2=%s r2=%s' % (d2, r2), file=sys.stderr)
	return d2 <= r2
t = int(input())
for _ in range(t):
	(r1, r2) = map(int, input().split())
	c1 = tuple(map(int, input().split()))
	a1 = tuple(map(int, input().split()))
	c2 = tuple(map(int, input().split()))
	a2 = tuple(map(int, input().split()))
	if solve(c1, r1, a1, c2, r2, a2):
		print('YES')
	else:
		print('NO')


def diff(x, y):
	return [a - b for (a, b) in zip(x, y)]

def dot(x, y):
	return sum((a * b for (a, b) in zip(x, y)))

def mindistsq(p, v):
	if dot(p, v) >= 0:
		return dot(p, p)
	else:
		return dot(p, p) - dot(p, v) ** 2 / dot(v, v)
n = int(input())
for _ in range(n):
	r = [int(x) for x in input().split()]
	p1 = [int(x) for x in input().split()]
	a1 = [int(x) for x in input().split()]
	p2 = [int(x) for x in input().split()]
	a2 = [int(x) for x in input().split()]
	if mindistsq(diff(p1, p2), diff(a1, a2)) <= sum(r) ** 2:
		print('YES')
	else:
		print('NO')


import sys, math
n = int(input().strip())

def dist(p, a, t):
	d = [(p[i] + a[i] * t ** 2 / 2) ** 2 for i in range(3)]
	return math.sqrt(sum(d))
for i in range(n):
	[R1, R2] = map(int, input().strip().split())
	[x1, y1, z1] = map(int, input().strip().split())
	[a1x, a1y, a1z] = map(int, input().strip().split())
	[x2, y2, z2] = map(int, input().strip().split())
	[a2x, a2y, a2z] = map(int, input().strip().split())
	p = [x2 - x1, y2 - y1, z2 - z1]
	a = [a2x - a1x, a2y - a1y, a2z - a1z]
	den = sum([a[i] ** 2 for i in range(3)])
	t2 = 0
	if den != 0:
		t2 = sum([-2.0 * p[i] * a[i] for i in range(3)]) / den
	t = 0
	if t2 > 0:
		t = math.sqrt(t2)
	if dist(p, a, t) <= R1 + R2:
		print('YES')
	else:
		print('NO')


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = sys.stdin.readline()
for i in range(int(N)):
	print_contact(sys.stdin)


import math

def pos(start, accel, t):
	tt = t * t
	return [accel[i] * tt / 2.0 + start[i] for i in range(3)]

def d_sqr(start0, accel0, start1, accel1, t):
	pos0 = pos(start0, accel0, t)
	pos1 = pos(start1, accel1, t)
	diff = [pos0[i] - pos1[i] for i in range(3)]
	return sum([x * x for x in diff])

def status(f, t, delta):
	a = f(t - delta)
	b = f(t)
	c = f(t + delta)
	if a == b and b == c:
		return 0
	if a >= b and b >= c:
		return -1
	if a <= b and b <= c:
		return 1
	return 0

def min_dist_sqr(start0, accel0, start1, accel1, target):
	f = lambda t: d_sqr(start0, accel0, start1, accel1, t)
	delta = 1e-05
	t_hi = 0.1
	while status(f, t_hi, delta) == -1:
		t_hi *= 2.0
	t_lo = 0.0
	while t_hi - t_lo > 10 * delta:
		mid = (t_hi + t_lo) / 2.0
		s = status(f, mid, delta)
		if s == 0:
			break
		if s == -1:
			t_lo = mid
		else:
			t_hi = mid
	mid = (t_hi + t_lo) / 2.0
	return math.sqrt(f(mid))
num_q = int(input())
for _ in range(num_q):
	(r1, r2) = (int(x) for x in input().split())
	start0 = [float(x) for x in input().split()]
	accel0 = [float(x) for x in input().split()]
	start1 = [float(x) for x in input().split()]
	accel1 = [float(x) for x in input().split()]
	min_d = min_dist_sqr(start0, accel0, start1, accel1, (r1 + r2) * (r1 + r2))
	if min_d < r1 + r2:
		print('YES')
	else:
		print('NO')


import math

def getdistance(pos1, pos2):
	squared_sums = [(i - j) ** 2 for (i, j) in zip(pos1, pos2)]
	return math.sqrt(sum(squared_sums))

def contact(rad1, rad2, pos1, acc1, pos2, acc2):
	distance_old = getdistance(pos1, pos2) + 1
	while True:
		pos1 = [pos + acc * 0.01 for (pos, acc) in zip(pos1, acc1)]
		pos2 = [pos + acc * 0.01 for (pos, acc) in zip(pos2, acc2)]
		distance = getdistance(pos1, pos2)
		if distance > distance_old:
			return 'NO'
		distance_old = distance
		if distance <= rad1 + rad2:
			return 'YES'
cases = int(input())
for case in range(cases):
	(rad1, rad2) = input().split(' ')
	(rad1, rad2) = (int(rad1), int(rad2))
	pos1 = [int(i) for i in input().split(' ')]
	acc1 = [int(i) for i in input().split(' ')]
	pos2 = [int(i) for i in input().split(' ')]
	acc2 = [int(i) for i in input().split(' ')]
	print(contact(rad1, rad2, pos1, acc1, pos2, acc2))


import math
n = int(input())
for _ in range(n):
	(r1, r2) = map(int, input().strip().split(' '))
	c1 = list(map(int, input().strip().split(' ')))
	a1 = list(map(int, input().strip().split(' ')))
	c2 = list(map(int, input().strip().split(' ')))
	a2 = list(map(int, input().strip().split(' ')))
	for i in range(3):
		a1[i] /= 2
		a2[i] /= 2
	count = 0
	k_1 = (r1 + r2) ** 2
	c_x = c2[0] - c1[0]
	c_y = c2[1] - c1[1]
	c_z = c2[2] - c1[2]
	a_x = a2[0] - a1[0]
	a_y = a2[1] - a1[1]
	a_z = a2[2] - a1[2]
	const_sum_sq = c_x ** 2 + c_y ** 2 + c_z ** 2
	a = a_x ** 2 + a_y ** 2 + a_z ** 2
	b = 2 * (a_x * c_x + a_y * c_y + a_z * c_z)
	c = const_sum_sq - k_1
	discr = b ** 2 - 4 * a * c
	if discr < 0:
		print('NO')
	else:
		discr = math.sqrt(discr)
		root_1 = (-1 * b + discr) / (2 * a)
		root_2 = (-1 * b - discr) / (2 * a)
		if root_1 >= 0 or root_2 >= 0:
			print('YES')
		else:
			print('NO')


from math import sqrt
t = int(input())
for aaaaa in range(t):
	(r1, r2) = list(map(int, input().split()))
	(x1, y1, z1) = list(map(int, input().split()))
	(ax1, ay1, az1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	(ax2, ay2, az2) = list(map(int, input().split()))
	summedDistanceSquared = (r1 + r2) * (r1 + r2)
	deltaX = x1 - x2
	deltaY = y1 - y2
	deltaZ = z1 - z2
	deltaAX = ax1 - ax2
	deltaAY = ay1 - ay2
	deltaAZ = az1 - az2
	alpha = deltaAX ** 2 + deltaAY ** 2 + deltaAZ ** 2
	beta = 2 * (deltaX * deltaAX + deltaY * deltaAY + deltaZ * deltaAZ)
	gamma = deltaX ** 2 + deltaY ** 2 + deltaZ ** 2 - summedDistanceSquared
	discA = beta ** 2 - 4 * alpha * gamma
	if discA < 0:
		print('NO')
	else:
		a1 = (-1 * beta + sqrt(discA)) / (2.0 * alpha)
		a2 = (-1 * beta - sqrt(discA)) / (2.0 * alpha)
		if a1 < 0 and a2 < 0:
			print('NO')
		else:
			print('YES')


class Vec:

	def __init__(self, x, y, z):
		self.x = x
		self.y = y
		self.z = z

	def dot(self, other):
		return self.x * other.x + self.y * other.y + self.z * other.z

	def __sub__(self, other):
		return Vec(self.x - other.x, self.y - other.y, self.z - other.z)

def willcollide(x1, a1, x2, a2, R1, R2):
	deltaX = x1 - x2
	deltaA = a1 - a2
	if deltaX.dot(deltaA) >= 0:
		return False
	minDistSquared = deltaX.dot(deltaX) - deltaX.dot(deltaA) ** 2 / deltaA.dot(deltaA)
	return minDistSquared <= (R1 + R2) ** 2
for _ in range(int(input())):
	(R1, R2) = map(int, input().split(' '))
	x1 = Vec(*map(int, input().split(' ')))
	a1 = Vec(*map(int, input().split(' ')))
	x2 = Vec(*map(int, input().split(' ')))
	a2 = Vec(*map(int, input().split(' ')))
	print('YES' if willcollide(x1, a1, x2, a2, R1, R2) else 'NO')


import sys
from math import sqrt
tc = int(sys.stdin.readline())
cases = []
outcomes = []
dist = lambda xl, yl: sqrt(sum([(x - y) ** 2 for (x, y) in zip(xl, yl)]))
position = lambda pil, al, t: tuple([pi + 1 / 2 * a * t ** 2 for (pi, a) in zip(pil, al)])
for i in range(tc):
	case = {}
	(case['r1'], case['r2']) = tuple(map(int, sys.stdin.readline().strip().split()))
	p1cur = tuple(map(int, sys.stdin.readline().strip().split()))
	a1 = tuple(map(int, sys.stdin.readline().strip().split()))
	p2cur = tuple(map(int, sys.stdin.readline().strip().split()))
	a2 = tuple(map(int, sys.stdin.readline().strip().split()))
	t = 0
	killLoop = False
	srad = case['r1'] + case['r2']
	initdist = dist(p1cur, p2cur)
	if initdist < srad:
		outcomes.append('YES')
	else:
		while not killLoop:
			inc = 0.1
			p1cur = position(p1cur, a1, inc)
			p2cur = position(p2cur, a2, inc)
			newdist = dist(p1cur, p2cur)
			if newdist <= srad:
				outcomes.append('YES')
				killLoop = True
			elif newdist > initdist:
				outcomes.append('NO')
				killLoop = True
			else:
				initdist = newdist
for x in outcomes:
	print(x)


import sys

def Contact(R, S1, A1, S2, A2):
	a = ((A1[0] - A2[0]) ** 2 + (A1[1] - A2[1]) ** 2 + (A1[2] - A2[2]) ** 2) / 4
	b = (S1[0] - S2[0]) * (A1[0] - A2[0]) + (S1[1] - S2[1]) * (A1[1] - A2[1]) + (S1[2] - S2[2]) * (A1[2] - A2[2])
	c = (S1[0] - S2[0]) ** 2 + (S1[1] - S2[1]) ** 2 + (S1[2] - S2[2]) ** 2 - (R[0] + R[1]) ** 2
	dd = b ** 2 - 4 * a * c
	if dd >= 0 and dd ** 0.5 >= b:
		return 'YES'
	else:
		return 'NO'
N = int(input())
for i in range(N):
	R = sys.stdin.readline().split()
	R = list(map(int, R))
	S1 = sys.stdin.readline().split()
	S1 = list(map(int, S1))
	A1 = sys.stdin.readline().split()
	A1 = list(map(int, A1))
	S2 = sys.stdin.readline().split()
	S2 = list(map(int, S2))
	A2 = sys.stdin.readline().split()
	A2 = list(map(int, A2))
	print(Contact(R, S1, A1, S2, A2))


import sys
import math
ls = sys.stdin.read().split()
number_of_test_cases = int(ls[0])
for i in range(number_of_test_cases):
	radius_1 = int(ls[i * 14 + 1])
	radius_2 = int(ls[i * 14 + 2])
	t0_r1 = [int(x) for x in ls[i * 14 + 3:i * 14 + 6]]
	a_r1 = [int(x) for x in ls[i * 14 + 6:i * 14 + 9]]
	t0_r2 = [int(x) for x in ls[i * 14 + 9:i * 14 + 12]]
	a_r2 = [int(x) for x in ls[i * 14 + 12:i * 14 + 15]]
	(x1, y1, z1) = (t0_r1[0], t0_r1[1], t0_r1[2])
	(x2, y2, z2) = (t0_r2[0], t0_r2[1], t0_r2[2])
	(r1_ax, r1_ay, r1_az) = (a_r1[0], a_r1[1], a_r1[2])
	(r2_ax, r2_ay, r2_az) = (a_r2[0], a_r2[1], a_r2[2])
	a = 0.25 * ((r1_ax - r2_ax) ** 2 + (r1_ay - r2_ay) ** 2 + (r1_az - r2_az) ** 2)
	b = (x1 - x2) * (r1_ax - r2_ax) + (y1 - y2) * (r1_ay - r2_ay) + (z1 - z2) * (r1_az - r2_az)
	c = (x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2 - (radius_1 + radius_2) ** 2
	if b ** 2 < 4 * a * c:
		print('NO')
	elif -1 * b + math.sqrt(b ** 2 - 4 * a * c) >= 0:
		print('YES')
	else:
		print('NO')


from math import sqrt

class vec:

	def __init__(self, x, y, z):
		self.x = x
		self.y = y
		self.z = z

	def __add__(self, obj):
		return vec(self.x + obj.x, self.y + obj.y, self.z + obj.z)

	def __sub__(self, obj):
		return vec(self.x - obj.x, self.y - obj.y, self.z - obj.z)

	def __str__(self):
		return (self.x, self.y, self.z).__str__()

	def mod(self):
		return sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2)

	def __mul__(self, obj):
		return self.x * obj.x + self.y * obj.y + self.z * obj.z

	@classmethod
	def string(cls, s):
		(x, y, z) = map(int, s.split())
		return cls(x, y, z)
for _ in range(int(input())):
	(r1, r2) = map(int, input().split())
	(p1, a1, p2, a2) = map(lambda x: vec.string(x), (input() for x in range(4)))
	l = a2 - a1
	r = p2 - p1
	d = sqrt(r.mod() ** 2 - (l * r / l.mod()) ** 2)
	angle = l * r / (l.mod() * r.mod())
	print('YES' if d <= r1 + r2 and angle < 0 else 'NO')


import os
import sys

def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import os
import sys
import math

def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import os
import sys

def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return list(map(int, stream.readline().strip().split()))

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import os
import sys

def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)


import os
import sys

def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def minus(A, B):
	return [a - b for (a, b) in zip(A, B)]

def contact(chi, alpha, rad):
	chi_sq = dot(chi, chi)
	chi_alpha = dot(chi, alpha)
	alpha_sq = dot(alpha, alpha)
	if chi_alpha > 0:
		return chi_sq <= rad ** 2
	return chi_sq - 1.0 * chi_alpha ** 2 / alpha_sq <= rad ** 2

def read_vector(stream):
	return map(int, stream.readline().strip().split())

def print_contact(stream):
	Rs = read_vector(stream)
	x1 = read_vector(stream)
	a1 = read_vector(stream)
	x2 = read_vector(stream)
	a2 = read_vector(stream)
	if contact(minus(x1, x2), minus(a1, a2), sum(Rs)):
		print('YES')
	else:
		print('NO')
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	print_contact(sys.stdin)