Jim likes to play with laser beams. 

Jim stays at point $(0,0)$. 

There is a mirror at point $(X_m,Y_m)$ and a wall between points $(X_1,Y_1)$ and $(X_2,Y_2)$.

Jim wants to find out if he can point the laser beam on the mirror.

Input Format 

First line contains the number of test cases, ${T}$. 

Each subsequent line contains one test case: space separated integers that denote endpoints of the wall $X_1,Y_1$, $X_2,Y_2$ and position of the mirror $X_m,Y_m$.  

Output Format 

The answer for each test case: Display YES if Jim can point the laser beam to the mirror, otherwise display NO .  

Constraints 

$1\leq T\leq100$ 

$0≤|X_1|,|Y_1|,|X_2|,|Y_2|,|X_m|,|Y_m|≤10^6$ 

Mirror doesn't have common points with wall. 

Wall doesn't pass through the point $(0,0)$.  

Sample Input

5
1 2 2 1 2 2
-1 1 1 1 1 -1
1 1 2 2 3 3
2 2 3 3 1 1
0 1 1 1 0 2

Sample Output

NO
YES
NO
YES
NO

Source: hackerrank | Difficulty: MEDIUM_HARD
Tags: Geometry


Solutions:
def det(a, b, c, d, e, f):
	return (a - e) * (d - f) - (b - f) * (c - e)
T = int(input())
for tt in range(T):
	(a, b, c, d, e, f) = [int(x) for x in input().split()]
	if det(a, b, c, d, e, f) == 0 and det(a, b, c, d, 0, 0) == 0:
		print('YES' if (0 - a) * (e - a) >= 0 and (0 - b) * (e - b) >= 0 else 'NO')
	elif det(a, b, c, d, e, f) * det(a, b, c, d, 0, 0) <= 0 and det(0, 0, e, f, a, b) * det(0, 0, e, f, c, d) <= 0:
		print('NO')
	else:
		print('YES')


def ccw(Ax, Ay, Bx, By, Cx, Cy):
	return (Cy - Ay) * (Bx - Ax) > (By - Ay) * (Cx - Ax)

def intersect(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy):
	if Cx != Ax and Dx != Bx:
		if (Cy - Ay) / (Cx - Ax) == (Dy - By) / (Dx - Bx):
			list1 = [Ax, Bx]
			list2 = [Cx, Dx]
			list1.sort()
			list2.sort()
			if max(list1) >= min(list2) or max(list2) >= min(list1):
				return True
			else:
				return False
	return ccw(Ax, Ay, Cx, Cy, Dx, Dy) != ccw(Bx, By, Cx, Cy, Dx, Dy) and ccw(Ax, Ay, Bx, By, Cx, Cy) != ccw(Ax, Ay, Bx, By, Dx, Dy)

def calculate(Ax, Ay, Bx, By, Mx, My):
	return intersect(Ax, Ay, Bx, By, Mx, My, 0, 0)
tcs = int(input())
for tc in range(tcs):
	(a, b, c, d, e, f) = map(int, input().split(' '))
	if not calculate(a, b, c, d, e, f):
		print('YES')
	else:
		print('NO')


t = int(input())

def signum(x):
	if x == 0:
		return 0
	else:
		return 1 if x > 0 else -1

def turn(p0, p1, p2):
	return signum((p1[0] - p0[0]) * (p2[1] - p0[1]) - (p2[0] - p0[0]) * (p1[1] - p0[1]))
Z = (0, 0)

def rect_intersect(p1, p2, p3, p4):
	return oneD_inter(p1[0], p2[0], p3[0], p4[0]) and oneD_inter(p1[1], p2[1], p3[1], p4[1])

def oneD_inter(a, b, c, d):
	if a > b:
		(a, b) = (b, a)
	if c > d:
		(c, d) = (d, c)
	return max(a, c) <= min(b, d)

def block(p1, p2, pm):
	if pm == (0, 0):
		return True
	t1m = turn(Z, p1, pm)
	tm2 = turn(Z, pm, p2)
	if t1m == 0 and tm2 == 0:
		return rect_intersect(Z, pm, p1, p2)
	if t1m * tm2 < 0:
		return False
	pr = turn(p1, Z, p2) * turn(p1, p2, pm)
	if pr < 0:
		return False
	return True
for _ in range(t):
	(x1, y1, x2, y2, x3, y3) = map(int, input().split())
	p1 = (x1, y1)
	p2 = (x2, y2)
	pm = (x3, y3)
	print('NO' if block(p1, p2, pm) else 'YES')


def equationLine2D(x1, y1, x2, y2):
	if x2 - x1 == 0:
		return (1e+99, 0)
	a = (y2 - y1) / (x2 - x1)
	b = y1 - a * x1
	return (a, b)

def intersectionPoint2D(a1, b1, a2, b2):
	if a2 - a1 == 0:
		return (False, False)
	x = (b1 - b2) / (a2 - a1)
	y = a1 * x + b1
	return (x, y)

def scalarProduct2D(dx1, dy1, dx2, dy2):
	return dx1 * dx2 + dy1 * dy2

def distL2(dx, dy):
	return (dx ** 2 + dy ** 2) ** 0.5
T = int(input())
for _ in range(T):
	(xA, yA, xB, yB, xM, yM) = map(int, input().split())
	(aAB, bAB) = equationLine2D(xA, yA, xB, yB)
	(aOM, bOM) = equationLine2D(0, 0, xM, yM)
	(xI, yI) = intersectionPoint2D(aAB, bAB, aOM, bOM)
	if xI == False and yI == False:
		(dxOA, dyOA) = (xA, yA)
		(dxOB, dyOB) = (xB, yB)
		(dxOM, dyOM) = (xM, yM)
		scalProdOAOM = scalarProduct2D(dxOA, dyOA, dxOM, dyOM)
		distOA = distL2(dxOA, dyOA)
		distOB = distL2(dxOB, dyOB)
		distOM = distL2(dxOM, dyOM)
		if bAB == bOM and scalProdOAOM >= 0 and (distOM > min(distOA, distOB)):
			print('NO')
		else:
			print('YES')
		continue
	(dxAI, dyAI) = (xI - xA, yI - yA)
	(dxAB, dyAB) = (xB - xA, yB - yA)
	scalProdAIAB = scalarProduct2D(dxAI, dyAI, dxAB, dyAB)
	distAB = distL2(dxAB, dyAB)
	distAI = distL2(dxAI, dyAI)
	(dxOI, dyOI) = (xI, yI)
	(dxOM, dyOM) = (xM, yM)
	scalProdOIOM = scalarProduct2D(dxOI, dyOI, dxOM, dyOM)
	distOM = distL2(dxOM, dyOM)
	distOI = distL2(dxOI, dyOI)
	if scalProdAIAB >= 0 and distAI <= distAB and (scalProdOIOM >= 0) and (distOI <= distOM):
		print('NO')
	else:
		print('YES')


class Point:

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

	def isNotBetweenOf(self, p1, p2):
		return p1.x < self.x and p2.x < self.x or (p1.x > self.x and p2.x > self.x)

	def __repr__(self):
		return '({}, {})'.format(self.x, self.y)

class StLine:

	def __init__(self, p1, p2):
		if p1.x != p2.x:
			self.a = -(p1.y - p2.y) / (p1.x - p2.x)
			self.b = 1
			self.c = p1.y + self.a * p1.x
		elif p1.y != p2.y:
			self.a = 1
			self.b = 0
			self.c = p1.x

	def separates(self, p1, p2):
		aVal = self.a * p1.x + self.b * p1.y - self.c
		bVal = self.a * p2.x + self.b * p2.y - self.c
		return aVal < 0 and bVal > 0 or (aVal > 0 and bVal < 0)

	def satisfies(self, p):
		return self.a * p.x + self.b * p.y == self.c

	def solve(self, st):
		if self.a * st.b == st.a * self.b:
			return None
		else:
			return Point((self.c * st.b - self.b * st.c) / (self.a * st.b - st.a * self.b), (self.c * st.a - self.a * st.c) / (self.b * st.a - st.b * self.a))

	def __repr__(self):
		return '{}*x + {}*y = {}'.format(self.a, self.b, self.c)

def func(p1, p2, p):
	org = Point(0, 0)
	laser = StLine(p, org)
	if laser.satisfies(p1) and (not p1.isNotBetweenOf(p, org)) or (laser.satisfies(p2) and (not p2.isNotBetweenOf(p, org))):
		return False
	elif not laser.separates(p1, p2):
		return True
	wall = StLine(p1, p2)
	solP = wall.solve(laser)
	if solP == None:
		return p1.isNotBetweenOf(p, org) and p2.isNotBetweenOf(p, org)
	else:
		return solP.isNotBetweenOf(p, org)
for i in range(int(input())):
	li = [int(i) for i in input().split()]
	p1 = Point(li[0], li[1])
	p2 = Point(li[2], li[3])
	p = Point(li[4], li[5])
	print('YES' if func(p1, p2, p) else 'NO')


def cp(a, b):
	return a[0] * b[1] - a[1] * b[0]

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

def cr(p1, p2, q1, q2):
	for i in range(2):
		if max(p1[i], p2[i]) < min(q1[i], q2[i]) or min(p1[i], p2[i]) > max(q1[i], q2[i]):
			return False
	return cp(d(q2, q1), d(p1, q1)) * cp(d(q2, q1), d(p2, q1)) <= 0 and cp(d(p2, p1), d(q1, p1)) * cp(d(p2, p1), d(q2, p1)) <= 0
for ti in range(int(input())):
	(x1, y1, x2, y2, x3, y3) = map(int, input().split())
	print('NO' if cr((x1, y1), (x2, y2), (0, 0), (x3, y3)) else 'YES')


t = int(input())
for _ in range(t):
	ID = input().split()
	a = []
	for x in ID:
		a.append(int(x))
	flag = True
	g = False
	if a[0] * a[5] == a[1] * a[4] and a[0] * a[0] + a[1] * a[1] < a[4] * a[4] + a[5] * a[5]:
		g = True
	if a[2] * a[5] == a[3] * a[4] and a[2] * a[2] + a[3] * a[3] < a[4] * a[4] + a[5] * a[5]:
		g = True
	if (a[2] * a[5] - a[3] * a[4] > 0) == (a[0] * a[5] - a[1] * a[4] > 0):
		flag = False
	(a[0], a[1], a[2], a[3], a[4], a[5]) = (-a[0], -a[1], a[4] - a[0], a[5] - a[1], a[2] - a[0], a[3] - a[1])
	if (a[2] * a[5] - a[3] * a[4] > 0) == (a[0] * a[5] - a[1] * a[4] > 0):
		flag = False
	if g == True:
		flag = True
	if flag == True:
		print('NO')
	else:
		print('YES')


def p3_to_v2(o, p1, p2):
	v1 = (p1[0] - o[0], p1[1] - o[1])
	v2 = (p2[0] - o[0], p2[1] - o[1])
	return (v1, v2)

def s_to_p2(seg):
	p1 = (seg[0], seg[1])
	p2 = (seg[2], seg[3])
	return (p1, p2)

def dot(o, p1, p2):
	(v1, v2) = p3_to_v2(o, p1, p2)
	return v1[0] * v2[0] + v1[1] * v2[1]

def cross(o, p1, p2):
	(v1, v2) = p3_to_v2(o, p1, p2)
	return v1[0] * v2[1] - v1[1] * v2[0]

def side(seg, point):
	(p1, p2) = s_to_p2(seg)
	return cross(point, p1, p2)

def point_in_seg(seg, point):
	(p1, p2) = s_to_p2(seg)
	return cross(point, p1, p2) == 0 and dot(point, p1, p2) <= 0

def intersect(seg_1, seg_2):
	(p1_1, p1_2) = s_to_p2(seg_1)
	(p2_1, p2_2) = s_to_p2(seg_2)
	c1 = side(seg_1, p2_1) * side(seg_1, p2_2)
	c2 = side(seg_2, p1_1) * side(seg_2, p1_2)
	if c1 > 0 or c2 > 0:
		return False
	if c1 < 0 and c2 < 0:
		return True
	return point_in_seg(seg_1, p2_1) or point_in_seg(seg_1, p2_2) or point_in_seg(seg_2, p1_1) or point_in_seg(seg_2, p1_2)
T = int(input())
for _ in range(T):
	(X1, Y1, X2, Y2, Xm, Ym) = map(int, input().split())
	if intersect((X1, Y1, X2, Y2), (0, 0, Xm, Ym)):
		print('NO')
	else:
		print('YES')


def findCross(arr):
	x1 = arr[0]
	y1 = arr[1]
	x2 = arr[2]
	y2 = arr[3]
	a = arr[4]
	b = arr[5]
	c = ((b - y2) * (x2 - x1) - (y2 - y1) * (a - x2)) * ((0 - y2) * (x2 - x1) - (y2 - y1) * (0 - x2))
	if c > 0:
		return True
	d = (y2 * a - x2 * b) * (y2 * x1 - x2 * y1)
	if d < 0:
		return True
	e = (y1 * a - x1 * b) * (y1 * x2 - x1 * y2)
	if e < 0:
		return True
	if e == 0 and d == 0 and (a < x2) and (a < x1) and (b < y2) and (b < y1):
		return True
	return False

def main():
	T = int(input())
	for x in range(T):
		n = input().split(' ')
		f = []
		for x in n:
			f.append(int(x))
		val = findCross(f)
		if val:
			print('YES')
		else:
			print('NO')
main()


def side(a, b, c):
	d = (c[1] - a[1]) * (b[0] - a[0]) - (b[1] - a[1]) * (c[0] - a[0])
	return 1 if d > 0 else -1 if d < 0 else 0

def is_point_in_closed_segment(a, b, c):
	if a[0] < b[0]:
		return a[0] <= c[0] and c[0] <= b[0]
	if b[0] < a[0]:
		return b[0] <= c[0] and c[0] <= a[0]
	if a[1] < b[1]:
		return a[1] <= c[1] and c[1] <= b[1]
	if b[1] < a[1]:
		return b[1] <= c[1] and c[1] <= a[1]
	return a[0] == c[0] and a[1] == c[1]

def closed_segment_intersect(a, b, c, d):
	if a == b:
		return a == c or a == d
	if c == d:
		return c == a or c == b
	s1 = side(a, b, c)
	s2 = side(a, b, d)
	if s1 == 0 and s2 == 0:
		return is_point_in_closed_segment(a, b, c) or is_point_in_closed_segment(a, b, d) or is_point_in_closed_segment(c, d, a) or is_point_in_closed_segment(c, d, b)
	if s1 and s1 == s2:
		return False
	s1 = side(c, d, a)
	s2 = side(c, d, b)
	if s1 and s1 == s2:
		return False
	return True
for _ in range(int(input())):
	(x1, y1, x2, y2, xm, ym) = map(int, input().split())
	a = (0, 0)
	b = (xm, ym)
	c = (x1, y1)
	d = (x2, y2)
	if closed_segment_intersect(a, b, c, d):
		print('NO')
	else:
		print('YES')


t = input()
l = []
for i in range(0, int(t)):
	m = input()
	a = m.split()
	a = [int(j) for j in a]
	l.append(a)
for i in l:
	if (i[-2] * i[1] - i[-1] * i[0]) * (i[-2] * i[3] - i[-1] * i[2]) > 0:
		print('YES')
	else:
		b = i[3] - i[1]
		c = i[2] - i[0]
		if (i[-2] * i[1] - i[-1] * i[0]) * (i[-2] * i[3] - i[-1] * i[2]) == 0 and (c * -i[1] + b * i[0]) * (c * (i[-1] - i[1]) - b * (i[-2] - i[0])) == 0:
			if abs(i[-2]) > abs(i[0]):
				print('NO')
			else:
				print('YES')
		elif (c * -i[1] + b * i[0]) * (c * (i[-1] - i[1]) - b * (i[-2] - i[0])) > 0:
			print('YES')
		else:
			print('NO')


def linear(a, x, b, y):
	return -a * x + b * y

def isInside(x1, y1, x2, y2, x, y):
	return (x1 <= x <= x2 or x2 <= x <= x1) and (y1 <= y <= y2 or y2 <= y <= y1)
t = int(input())
for n in range(0, t):
	(x1, y1, x2, y2, xm, ym) = [int(i) for i in input().strip().split()]
	(X, Y) = (x1, y1)
	(a, b) = (y2 - y1, x2 - x1)
	c = linear(a, x1, b, y1)
	d = linear(a, xm, b, ym)
	if d != 0:
		X = xm * c / d
		Y = ym * c / d
		print(('YES', 'NO')[isInside(x1, y1, x2, y2, X, Y) and isInside(0, 0, xm, ym, X, Y)])
	else:
		if xm == 0:
			isOnTop = xm / ym == x1 / y1
		else:
			isOnTop = ym / xm == y1 / x1
		print(('YES', 'NO')[isOnTop and isInside(0, 0, xm, ym, X, Y)])


t = int(input())

class Line:
	A = 0.0
	B = 0.0
	C = 0.0

	def __init__(self, x, y):
		self.A = y[1] - x[1]
		self.B = -(y[0] - x[0])
		self.C = -x[0] * (y[1] - x[1]) + x[1] * (y[0] - x[0])

	def value(self, point):
		return self.A * point[0] + self.B * point[1] + self.C

def intersect(x):
	return max(x[0], x[1]) >= min(x[2], x[3]) and min(x[0], x[1]) <= max(x[2], x[3])

def boundingBox(p):
	return intersect([p[0][0], p[1][0], p[2][0], p[3][0]]) and intersect([p[0][1], p[1][1], p[2][1], p[3][1]])

def differentSigns(x, y):
	return x <= 0 and 0 <= y or (y <= 0 and 0 <= x)
for i in range(t):
	data = input().split(' ')
	p = [0 for i in range(4)]
	for i in range(3):
		p[i] = (int(data[2 * i]), int(data[2 * i + 1]))
	p[3] = (0, 0)
	line1 = Line(p[0], p[1])
	line2 = Line(p[2], p[3])
	if differentSigns(line1.value(p[2]), line1.value(p[3])) and differentSigns(line2.value(p[0]), line2.value(p[1])) and boundingBox(p):
		print('NO')
	else:
		print('YES')


import sys

class Point:

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

class Line:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

	def intersect(self, anotherline):
		if min(self.p1.x, self.p2.x) > max(anotherline.p1.x, anotherline.p2.x):
			return False
		if min(self.p1.y, self.p2.y) > max(anotherline.p1.y, anotherline.p2.y):
			return False
		if min(anotherline.p1.x, anotherline.p2.x) > max(self.p1.x, self.p2.x):
			return False
		if min(anotherline.p1.y, anotherline.p2.y) > max(self.p1.y, self.p2.y):
			return False
		return self.__straddle(anotherline) and anotherline.__straddle(self)

	def __straddle(self, anotherline):
		return 0 >= self.__side(anotherline.p1) * self.__side(anotherline.p2)

	def __side(self, point):
		n = point.x * (self.p1.y - self.p2.y) + self.p1.x * (self.p2.y - point.y) + self.p2.x * (point.y - self.p1.y)
		if n > 0:
			return 1
		elif n < 0:
			return -1
		else:
			return 0

def calclaser(textline):
	(x1, y1, x2, y2, xm, ym) = map(int, textline.split())
	line1 = Line(Point(x1, y1), Point(x2, y2))
	lineM = Line(Point(0, 0), Point(xm, ym))
	if lineM.intersect(line1) == True:
		print('NO')
	else:
		print('YES')
line = sys.stdin.readline()
n = int(line)
for i in range(n):
	line = sys.stdin.readline()
	calclaser(line)


from fractions import Fraction

def bet(p, l1, l2):
	if p >= min(l1, l2) and p <= max(l1, l2):
		return True
	else:
		return False

def calc(x1, y1, x2, y2, xm, ym):
	if xm == 0:
		if x1 == x2:
			if x1 != 0:
				return False
			else:
				return bet(y1, 0, ym)
		else:
			return bet(y1 - x1 * Fraction(y1 - y2, x1 - x2), 0, ym) and bet(0, x1, x2)
	elif x1 == x2:
		return bet(Fraction(ym, xm) * x1, y1, y2) and bet(x1, 0, xm)
	else:
		mm = Fraction(ym, xm)
		mw = Fraction(y1 - y2, x1 - x2)
		b = y1 - mw * x1
		if mm == mw:
			if b != 0:
				return False
			else:
				return bet(y1, 0, ym)
		xint = Fraction(b, mm - mw)
		return bet(xint, 0, xm) and bet(xint, x1, x2)
t = int(input())
for i in range(t):
	(x1, y1, x2, y2, xm, ym) = [int(x) for x in input().split()]
	if calc(x1, y1, x2, y2, xm, ym):
		print('NO')
	else:
		print('YES')


def findPointSlope(a, b):
	diff = (b[0] - a[0], b[1] - a[1])
	if diff[0] == 0:
		return (a[0],)
	m = diff[1] / diff[0]
	b = a[1] - m * a[0]
	return (m, b)

def findIntersection(a, b):
	if len(a) == 1 or len(b) == 1:
		vert = None
		other = None
		if len(a) == 1:
			vert = a
			other = b
		else:
			vert = b
			other = a
		x = vert[0]
		y = other[0] * x + other[1]
		return (x, y)
	if a[0] - b[0] == 0:
		return None
	x = (b[1] - a[1]) / (a[0] - b[0])
	y = a[0] * x + a[1]
	return (x, y)

def isPointInInterval(p, i1, i2):
	return p[0] >= min(i1[0], i2[0]) and p[0] <= max(i1[0], i2[0]) and (p[1] >= min(i1[1], i2[1])) and (p[1] <= max(i1[1], i2[1]))
T = input()
for i in range(int(T)):
	data = input()
	points = data.split()
	wall1 = (int(points[0]), int(points[1]))
	wall2 = (int(points[2]), int(points[3]))
	mirror = (int(points[4]), int(points[5]))
	mirrormb = findPointSlope((0, 0), mirror)
	wallmb = findPointSlope(wall1, wall2)
	if wallmb == mirrormb and (isPointInInterval(wall1, (0, 0), mirror) or isPointInInterval(wall2, (0, 0), mirror)):
		print('NO')
		continue
	intersection = findIntersection(mirrormb, wallmb)
	if intersection and isPointInInterval(intersection, wall1, wall2) and isPointInInterval(intersection, (0, 0), mirror):
		print('NO')
	else:
		print('YES')


def side(a, b, c):
	d = (c[1] - a[1]) * (b[0] - a[0]) - (b[1] - a[1]) * (c[0] - a[0])
	return 1 if d > 0 else -1 if d < 0 else 0

def is_point_in_closed_segment(a, b, c):
	if a[0] < b[0]:
		return a[0] <= c[0] and c[0] <= b[0]
	if b[0] < a[0]:
		return b[0] <= c[0] and c[0] <= a[0]
	if a[1] < b[1]:
		return a[1] <= c[1] and c[1] <= b[1]
	if b[1] < a[1]:
		return b[1] <= c[1] and c[1] <= a[1]
	return a[0] == c[0] and a[1] == c[1]

def closed_segment_intersect(a, b, c, d):
	if a == b:
		return a == c or a == d
	if c == d:
		return c == a or c == b
	s1 = side(a, b, c)
	s2 = side(a, b, d)
	if s1 == 0 and s2 == 0:
		return is_point_in_closed_segment(a, b, c) or is_point_in_closed_segment(a, b, d) or is_point_in_closed_segment(c, d, a) or is_point_in_closed_segment(c, d, b)
	if s1 and s1 == s2:
		return False
	s1 = side(c, d, a)
	s2 = side(c, d, b)
	if s1 and s1 == s2:
		return False
	return True
for i in range(int(input())):
	lst = [int(j) for j in input().split(' ')]
	if closed_segment_intersect((0, 0), lst[4:], lst[:2], lst[2:4]):
		print('NO')
		continue
	print('YES')


import sys
source = sys.stdin

def sgn(x):
	if x > 0:
		return 1
	elif x < 0:
		return -1
	else:
		return 0

def in_los(xm, ym, x, y):
	if x * ym == y * xm:
		mag = x ** 2 + y ** 2
		magm = xm ** 2 + ym ** 2
		return mag <= magm and sgn(x) == sgn(xm) and (sgn(y) == sgn(ym))
	else:
		return False
T = int(source.readline())
for i in range(T):
	[x1, y1, x2, y2, xm, ym] = [int(s) for s in source.readline().split()]
	if in_los(xm, ym, x1, y1) or in_los(xm, ym, x2, y2):
		print('NO')
	else:
		D = xm * y1 - ym * x1
		if D == 0:
			print('YES')
		else:
			a = 1 / D * (y1 * x2 - x1 * y2)
			b = 1 / D * (y2 * xm - x2 * ym)
			if b == 1:
				print('YES')
			else:
				c = a / (1 - b)
				d = 1 / (1 - b)
				if d > 0 and d < 1 and (c > 0) and (c < 1):
					print('NO')
				else:
					print('YES')


t = int(input())
for _ in range(t):
	(x1, y1, x2, y2, xm, ym) = map(int, input().split())
	num1 = y2 * x1 - x2 * y1
	num2 = ym * x1 - xm * y1
	den = (y2 - y1) * xm - (x2 - x1) * ym
	if den < 0:
		hits = den < num1 <= 0 and den < num2 <= 0
	elif den > 0:
		hits = 0 <= num1 < den and 0 <= num2 < den
	elif num1 == 0 and num2 == 0:
		if xm < 0:
			hits = xm < x1 <= 0 or xm < x2 <= 0
		else:
			hits = 0 <= x1 < xm or 0 <= x2 < xm
	else:
		hits = False
	print('NO' if hits else 'YES')


T = int(input())
tests = []
for i in range(T):
	test = [int(i) for i in input().split()]
	tests.append(test)

def ccw(p1, p2, p3):
	(x1, y1, x2, y2, x3, y3) = (p1[0], p1[1], p2[0], p2[1], p3[0], p3[1])
	return (x2 - x1) * (y3 - y2) > (x3 - x2) * (y2 - y1)

def goes_back(x, y, z):
	return (x - y > 0) != (y - z > 0)

def overlaps(interval1, interval2):
	(p1, p2, p3, p4) = (interval1[0], interval1[1], interval2[0], interval2[1])
	return goes_back(p1, p2, p3) != goes_back(p1, p2, p4) or goes_back(p2, p1, p3) != goes_back(p2, p1, p4)

def collinear(p1, p2, p3):
	(x1, y1, x2, y2, x3, y3) = (p1[0], p1[1], p2[0], p2[1], p3[0], p3[1])
	return (x2 - x1) * (y3 - y2) == (x3 - x2) * (y2 - y1)

def dist(a, b):
	return sum([(a[i] - b[i]) ** 2 for i in range(len(a))]) ** 0.5

def intersects(seg1, seg2):
	(p1, p2, p3, p4) = (seg1[0], seg1[1], seg2[0], seg2[1])
	if collinear(p1, p2, p3) and collinear(p2, p3, p4):
		if overlaps((p1[0], p2[0]), (p3[0], p4[0])):
			return True
	if len(list(set([p1, p2, p3, p4]))) != 4:
		return False
	return ccw(p1, p2, p3) != ccw(p1, p2, p4) and ccw(p3, p4, p1) != ccw(p3, p4, p2)
for test in tests:
	seg1 = ((test[0], test[1]), (test[2], test[3]))
	seg2 = ((test[4], test[5]), (0, 0))
	if intersects(seg1, seg2):
		print('NO')
	else:
		print('YES')


def answer(wall_start, wall_end, mirror):
	wall_ray = [wall_end[0] - wall_start[0], wall_end[1] - wall_start[1]]
	if mirror == [0, 0]:
		ans = True
	elif wall_ray[1] * mirror[0] == wall_ray[0] * mirror[1]:
		if (wall_end[0] - mirror[0]) * mirror[1] == (wall_end[1] - mirror[1]) * mirror[0]:
			if mirror[0] == 0:
				tm_end = wall_end[1] / mirror[1]
				tm_start = wall_start[1] / mirror[1]
			else:
				tm_end = wall_end[0] / mirror[0]
				tm_start = wall_start[0] / mirror[0]
			tm_temp = tm_start
			tm_start = min(tm_start, tm_end)
			tm_end = max(tm_temp, tm_end)
			ans = tm_start > 1 or tm_end < 0
		else:
			ans = True
	elif mirror[0] == 0:
		tw = -wall_start[0] / wall_ray[0]
		tm = (wall_start[1] + wall_ray[1] * tw) / mirror[1]
		ans = (tm < 0 or tm > 1) or (tw < 0 or tw > 1)
	elif mirror[1] == 0:
		tw = wall_start[1] / wall_ray[1]
		tm = (wall_start[0] + wall_ray[0] * tw) / mirror[0]
		ans = (tm < 0 or tm > 1) or (tw < 0 or tw > 1)
	elif wall_ray == [0, 0]:
		ans = False
	elif wall_ray[0] == 0:
		tm = wall_start[0] / mirror[0]
		tw = (mirror[1] * tm - wall_start[1]) / wall_ray[1]
		ans = (tm < 0 or tm > 1) or (tw < 0 or tw > 1)
	elif wall_ray[1] == 0:
		tm = wall_start[1] / mirror[1]
		tw = (mirror[0] * tm - wall_start[0]) / wall_ray[0]
		ans = (tm < 0 or tm > 1) or (tw < 0 or tw > 1)
	else:
		tw = (wall_start[0] / mirror[0] - wall_start[1] / mirror[1]) / (wall_ray[1] / mirror[1] - wall_ray[0] / mirror[0])
		tm = (wall_start[0] + wall_ray[0] * tw) / mirror[0]
		ans = (tm < 0 or tm > 1) or (tw < 0 or tw > 1)
	if ans:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(0, t):
	(wallStartX, wallStartY, wallEndX, wallEndY, mirrorX, mirrorY) = map(int, input().split())
	print(answer([wallStartX, wallStartY], [wallEndX, wallEndY], [mirrorX, mirrorY]))


def in_order(a, b, c):
	return a <= b <= c or a >= b >= c

def equation(x1, y1, x2, y2):
	m = None if x2 == x1 else (y2 - y1) / (x2 - x1)
	b = x1 if m is None else y1 - m * x1
	return (m, b)
for _ in range(int(input())):
	(x1, y1, x2, y2, xm, ym) = map(int, input().split())
	(m1, b1) = equation(x1, y1, x2, y2)
	(m2, b2) = equation(0, 0, xm, ym)
	if m1 == m2:
		print('NO' if b1 == b2 and (in_order(0, x1, xm) and in_order(0, y1, ym) or (in_order(0, x2, xm) and in_order(0, y2, ym))) else 'YES')
	else:
		if m1 is not None and m2 is not None:
			x = (b2 - b1) / (m1 - m2)
			y = m1 * x + b1
		elif m1 is None:
			x = b1
			y = m2 * x + b2
		else:
			x = b2
			y = m1 * x + b1
		print('NO' if in_order(x1, x, x2) and in_order(y1, y, y2) and in_order(0, x, xm) and in_order(0, y, ym) else 'YES')


from sys import stdin
from math import sqrt
t = int(stdin.readline())
for ti in range(t):
	(x1, y1, x2, y2, xm, ym) = tuple([float(x) for x in stdin.readline().split()])
	try:
		b = (xm * y1 - ym * x1) / (x2 * y1 - y2 * x1)
		a = (ym - b * y2) / y1
		if a >= 0 and b >= 0 and (a + b > 1):
			print('NO')
		else:
			print('YES')
	except ZeroDivisionError:
		if ym * x1 == xm * y1 and (x1 != 0 and xm / x1 > 1 or (x2 != 0 and xm / x2 > 2)):
			print('NO')
		else:
			print('YES')


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

def dot(a, b):
	return a[0] * b[0] + a[1] * b[1]
T = int(input())
for case in range(T):
	(X1, Y1, X2, Y2, Xm, Ym) = read_ints()
	dx = X1 - X2
	dy = Y1 - Y2
	d = Xm * dy - Ym * dx
	res = 1
	if d != 0:
		t = (dy * X1 - dx * Y1) * d
		u = (Xm * Y1 - Ym * X1) * d
		d2 = d * d
		if t >= 0 and t <= d2 and (u >= 0) and (u <= d2):
			res = 0
	elif X1 * Ym == Y1 * Xm:
		t = X1 * Xm
		u = X2 * Xm
		d2 = Xm * Xm
		if t >= 0 and t <= d2 or (u >= 0 and u <= d2):
			res = 0
	if res:
		print('YES')
	else:
		print('NO')


N = int(input())

def edge_intersects(x, y):
	if x * ym != xm * y:
		return False
	if xm != 0:
		t = x / xm
	else:
		t = y / ym
	return t >= 0 and t <= 1
for _ in range(N):
	(x1, y1, x2, y2, xm, ym) = (int(x) for x in input().split())
	mat = [[x1 - x2, -xm], [y1 - y2, -ym]]
	b = [-x2, -y2]
	det = mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]
	if det == 0:
		if edge_intersects(x1, y1) or edge_intersects(x2, y2):
			print('NO')
		else:
			print('YES')
	else:
		inv = [[mat[1][1] / det, -mat[0][1] / det], [-mat[1][0] / det, mat[0][0] / det]]
		sol = [inv[0][0] * b[0] + inv[0][1] * b[1], inv[1][0] * b[0] + inv[1][1] * b[1]]
		soltest = [x >= 0 and x <= 1 for x in sol]
		if all(soltest):
			print('NO')
		else:
			print('YES')


import sys

class Point:

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

	def det(self, other):
		return self.x * other.y - self.y * other.x

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

	def norm_sq(self):
		return self.x * self.x + self.y * self.y

	def past(self, other):
		return self.det(other) == 0 and self.dot(other) > 0 and (self.norm_sq() >= other.norm_sq())
tc_len = int(sys.stdin.readline())
for tc in range(tc_len):
	(x1, y1, x2, y2, xm, ym) = tuple((int(x) for x in sys.stdin.readline().split()))
	p1 = Point(x1, y1)
	p2 = Point(x2, y2)
	pm = Point(xm, ym)
	va = Point(x2 - x1, y2 - y1)
	vb = Point(xm - x1, ym - y1)
	if pm.past(p1) or pm.past(p2):
		print('NO')
	elif pm.det(p1) * pm.det(p2) >= 0:
		print('YES')
	elif va.det(p1) * va.det(vb) <= 0:
		print('YES')
	else:
		print('NO')


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

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

def cross(x1, y1, x2, y2, xm, ym):
	return (x1 - xm) * (y2 - ym) - (y1 - ym) * (x2 - xm)
T = read_int()
for _ in range(T):
	(X1, Y1, X2, Y2, Xm, Ym) = read_ints()
	cm = cross(X1, Y1, X2, Y2, Xm, Ym)
	c0 = cross(X1, Y1, X2, Y2, 0, 0)
	ic1 = cross(0, 0, Xm, Ym, X1, Y1)
	ic2 = cross(0, 0, Xm, Ym, X2, Y2)
	if cm == c0 == 0:
		if X1 * (Xm - X1) <= 0 and Y1 * (Xm - Y1) <= 0:
			print('YES')
		else:
			print('NO')
	elif cm * c0 <= 0 and ic1 * ic2 <= 0:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	(x1, y1, x2, y2, xm, ym) = map(int, input().split())
	d = x1 * y2 - x2 * y1
	u = x1 * ym - xm * y1
	v = y2 * xm - ym * x2
	if d == 0:
		if u == 0:
			if xm / x1 >= 1 or xm / x2 >= 1:
				print('NO')
			else:
				print('YES')
		else:
			print('YES')
	else:
		u /= d
		v /= d
		if 0 <= u and 0 <= v and (1 <= u + v):
			print('NO')
		else:
			print('YES')


from math import sqrt
epsilon = 10 ** (-6)

def dist(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
for _ in range(int(input().strip())):
	(x1, y1, x2, y2, xm, ym) = map(int, input().split())
	if xm == 0 and ym == 0:
		print('YES')
		continue
	if x1 == x2 and y1 == y2:
		if dist(0, 0, x1, y1) + dist(x1, y1, xm, ym) == dist(0, 0, xm, ym):
			print('NO')
			continue
		else:
			print('YES')
			continue
	if ym * (x2 - x1) + xm * (y1 - y2) == 0:
		if x2 * y1 - x1 * y2 == 0:
			if dist(0, 0, xm, ym) > dist(0, 0, x1, y1) or dist(0, 0, xm, ym) > dist(0, 0, x2, y2):
				print('NO')
				continue
			else:
				print('YES')
				continue
		else:
			print('YES')
			continue
	a = (x2 * y1 - x1 * y2) / (ym * (x2 - x1) + xm * (y1 - y2))
	(x0, y0) = (a * xm, a * ym)
	c1 = abs(dist(0, 0, x0, y0) + dist(xm, ym, x0, y0) - dist(0, 0, xm, ym)) < epsilon
	c2 = abs(dist(x1, y1, x0, y0) + dist(x2, y2, x0, y0) - dist(x1, y1, x2, y2)) < epsilon
	if c1 and c2:
		print('NO')
	else:
		print('YES')


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

def crossprod(x, y):
	return x[0] * y[1] - x[1] * y[0]

def dotprod(x, y):
	return sum((i * j for (i, j) in zip(x, y)))
for _ in range(int(input())):
	(x1, y1, x2, y2, xm, ym) = [int(a) for a in input().split()]
	(q, v, r) = ([x1, y1], [x2, y2], [xm, ym])
	s = vsum(v, q, 1, -1)
	(a, b, c) = (crossprod(q, r), crossprod(q, s), crossprod(r, s))
	if c == 0 and a == 0:
		d = dotprod(r, r)
		t0 = dotprod(q, r)
		t1 = t0 + dotprod(s, r)
		if 0 <= t0 <= d or 0 <= t1 <= d:
			print('NO')
		else:
			print('YES')
	elif c == 0:
		print('YES')
	elif 0 <= b / c <= 1 and 0 <= a / c <= 1:
		print('NO')
	else:
		print('YES')


import math
line = input()
ctest = int(line)
for itest in range(ctest):
	line = input()
	tokens = line.split()
	X1 = int(tokens[0])
	Y1 = int(tokens[1])
	X2 = int(tokens[2])
	Y2 = int(tokens[3])
	XM = int(tokens[4])
	YM = int(tokens[5])
	theta1 = math.atan2(Y1, X1)
	theta2 = math.atan2(Y2, X2)
	if abs(theta1 - theta2) > math.pi:
		if theta2 < 0:
			theta2 += 2 * math.pi
		else:
			theta1 += 2 * math.pi
	if theta2 > theta1:
		(theta1, theta2) = (theta2, theta1)
		(X1, X2) = (X2, X1)
		(Y1, Y2) = (Y2, Y1)
	thetaM = math.atan2(YM, XM)
	if theta1 >= thetaM:
		if abs(theta1 - thetaM) > 2 * math.pi:
			thetaM += 2 * math.pi
		if theta2 > thetaM:
			print('YES')
			continue
	else:
		print('YES')
		continue
	dM = math.sqrt(XM ** 2 + YM ** 2)
	if theta1 == theta2:
		dL = min(math.sqrt(X1 ** 2 + Y1 ** 2), math.sqrt(X2 ** 2 + Y2 ** 2))
	else:
		dL = ((Y2 - Y1) * X2 - (X2 - X1) * Y2) / ((Y2 - Y1) * math.cos(thetaM) - (X2 - X1) * math.sin(thetaM))
	if dM < dL:
		print('YES')
	else:
		print('NO')


import sys

def get_z(p1, p2, p3):
	v1 = (p2[0] - p1[0], p2[1] - p1[1])
	v2 = (p3[0] - p1[0], p3[1] - p1[1])
	return v1[0] * v2[1] - v1[1] * v2[0]

def solve(p1, p2, m):
	print('p1=%s p2=%s m=%s' % (p1, p2, m), file=sys.stderr)
	o = (0, 0)
	z1 = get_z(o, m, p1)
	z2 = get_z(o, m, p2)
	z3 = get_z(p1, p2, o)
	z4 = get_z(p1, p2, m)
	print('z1=%s z2=%s z3=%s z4=%s' % (z1, z2, z3, z4), file=sys.stderr)
	if z1 == 0 and z2 == 0 and (z3 == 0) and (z4 == 0):
		(xmax, xmin, ymax, ymin) = (max(p1[0], p2[0]), min(p1[0], p2[0]), max(p1[1], p2[1]), min(p1[1], p2[1]))
		print('xmin=%d xmax=%d ymin=%d ymax=%d' % (xmin, xmax, ymin, ymax), file=sys.stderr)
		if xmax < 0 and xmax < m[0] or (xmin > 0 and xmin > m[0]):
			return True
		if ymax < 0 and ymax < m[1] or (ymin > 0 and ymin > m[1]):
			return True
		return False
	if z1 * z2 < 0 and z3 * z4 < 0:
		return False
	if z1 * z2 == 0:
		p = p1
		if z2 == 0:
			p = p2
		print('p=%s' % (p,), file=sys.stderr)
		if p[0] < 0 and m[0] > p[0] or (p[0] > 0 and m[0] < p[0]):
			return True
		if p[1] < 0 and m[1] > p[1] or (p[1] > 0 and m[1] < p[1]):
			return True
		return False
	return True
t = int(input())
for _ in range(t):
	(x1, y1, x2, y2, xm, ym) = map(int, input().split())
	if solve((x1, y1), (x2, y2), (xm, ym)):
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	(x1, y1, x2, y2, xm, ym) = map(int, input().strip().split(' '))
	if x1 * y2 - x2 * y1 > 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 > 0:
		print('YES')
	elif x1 * y2 - x2 * y1 < 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 < 0:
		print('YES')
	else:
		if ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 == 0:
			if y1 > ym and y2 > ym and (y1 > 0) and (y2 > 0) or (y1 < ym and y2 < ym and (y1 < 0) and (y2 < 0)):
				print('YES')
			else:
				print('NO')
			continue
		y_cord = (x2 * y1 - x1 * y2) / (x2 - x1 - xm / ym * (y2 - y1))
		if y_cord > y1 and y_cord > y2 or (y_cord < y1 and y_cord < y2):
			print('YES')
		else:
			print('NO')


from fractions import Fraction

def intersection(x1, y1, x2, y2, x3, y3, x4, y4):
	(a, b, e) = (x2 - x1, -(x4 - x3), x3 - x1)
	(c, d, f) = (y2 - y1, -(y4 - y3), y3 - y1)
	det = a * d - b * c
	if det == 0:
		if a * f - c * e == 0:
			norm2 = a * a + c * c
			t3 = Fraction(a * e + c * f, norm2)
			t4 = Fraction(a * (x4 - x1) + c * (y4 - y1), norm2)
			if t3 > t4:
				(t3, t4) = (t4, t3)
			return not (t4 < 0 or 1 < t3)
		return False
	(t, tp) = (Fraction(e * d - b * f, det), Fraction(a * f - e * c, det))
	return 0 <= t <= 1 and 0 <= tp <= 1

def main():
	T = int(input())
	for _ in range(T):
		(x1, y1, x2, y2, xm, ym) = map(int, input().split())
		print('YES' if not intersection(0, 0, xm, ym, x1, y1, x2, y2) else 'NO')
main()


n = int(input())
for _ in range(n):
	(x1, y1, x2, y2, xm, ym) = map(int, input().strip().split(' '))
	if x1 * y2 - x2 * y1 > 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 > 0:
		print('YES')
	elif x1 * y2 - x2 * y1 < 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 < 0:
		print('YES')
	else:
		if ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 == 0:
			if y1 > ym and y2 > ym and (y1 > 0) and (y2 > 0) or (y1 < ym and y2 < ym and (y1 < 0) and (y2 < 0)):
				print('YES')
			else:
				print('NO')
			continue
		y_cord = (x2 * y1 - x1 * y2) / (x2 - x1 - xm / ym * (y2 - y1))
		if y_cord > y1 and y_cord > y2 or (y_cord < y1 and y_cord < y2):
			print('YES')
		else:
			print('NO')


n = int(input())
for _ in range(n):
	(x1, y1, x2, y2, xm, ym) = map(int, input().strip().split(' '))
	if x1 * y2 - x2 * y1 > 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 > 0:
		print('YES')
	elif x1 * y2 - x2 * y1 < 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 < 0:
		print('YES')
	else:
		if ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 == 0:
			if y1 > ym and y2 > ym and (y1 > 0) and (y2 > 0) or (y1 < ym and y2 < ym and (y1 < 0) and (y2 < 0)):
				print('YES')
			else:
				print('NO')
			continue
		y_cord = (x2 * y1 - x1 * y2) / (x2 - x1 - xm / ym * (y2 - y1))
		if y_cord > y1 and y_cord > y2 or (y_cord < y1 and y_cord < y2):
			print('YES')
		else:
			print('NO')


def det(a, b, c, d, e, f):
	return (a - e) * (d - f) - (b - f) * (c - e)
T = int(input())
for tt in range(T):
	(a, b, c, d, e, f) = [int(x) for x in input().split()]
	if det(a, b, c, d, e, f) == 0 and det(a, b, c, d, 0, 0) == 0:
		print('YES' if (0 - a) * (e - a) >= 0 and (0 - b) * (e - b) >= 0 else 'NO')
	elif det(a, b, c, d, e, f) * det(a, b, c, d, 0, 0) <= 0 and det(0, 0, e, f, a, b) * det(0, 0, e, f, c, d) <= 0:
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	(x1, y1, x2, y2, xm, ym) = map(int, input().strip().split(' '))
	if x1 * y2 - x2 * y1 > 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 > 0:
		print('YES')
	elif x1 * y2 - x2 * y1 < 0 and ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 < 0:
		print('YES')
	else:
		if ym * (x2 - x1) - xm * (y2 - y1) + x1 * y2 - x2 * y1 == 0:
			if y1 > ym and y2 > ym and (y1 > 0) and (y2 > 0) or (y1 < ym and y2 < ym and (y1 < 0) and (y2 < 0)):
				print('YES')
			else:
				print('NO')
			continue
		y_cord = (x2 * y1 - x1 * y2) / (x2 - x1 - xm / ym * (y2 - y1))
		if y_cord > y1 and y_cord > y2 or (y_cord < y1 and y_cord < y2):
			print('YES')
		else:
			print('NO')