LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsConvex Hull
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Do the Segments Cross

EasyProblem #43
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Two segments can meet without crossing - touching at a single endpoint already counts.

A city planner is checking a stack of road proposals. Each proposal is a straight stretch of road between two points, and before anything gets built she needs to know which pairs of roads would run into each other.

You are given t pairs of segments. For each pair decide whether the two segments have at least one common point. A single shared point is enough - it does not matter whether the segments cross properly, only touch at an endpoint, or lie on top of each other along a whole stretch.

Input

The first line contains a single integer t - the number of testcases.

Each of the next t lines contains eight integers Ax​, Ay​, Bx​, By​, Cx​, Cy​, Dx​, Dy​ - the first segment goes from A to B and the second one from C to D.

Output

For every testcase print YES if the two segments have a common point, and NO otherwise.

Example

Input
5
0 0 4 4 0 4 4 0
0 0 4 4 0 10 10 0
0 0 4 4 4 4 8 0
0 0 4 4 2 2 6 6
0 0 4 4 1 0 5 4
Output
YES
NO
YES
YES
NO

The first pair crosses in the middle, at (2,2). In the second pair the two infinite lines do cross, but the segments themselves stop long before that. The third pair touches at the single point (4,4), the fourth pair lies on the same line and overlaps between (2,2) and (4,4), and the fifth pair is parallel.

Constraints

1≤t≤104
−109≤Ax​,Ay​,Bx​,By​,Cx​,Cy​,Dx​,Dy​≤109
A=B and C=D

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit