This page is still under construction.

Parts of this page are still being built. What you see may change.

Separating Lines

Time limit1sMemory limit128 MB

Summary
For each of up to 100000 query lines, report whether the given points fall on both sides of it or touch it.
Level

Medium7 of 10

Topics
Geometry, Binary search, Sorting
Solved
No attempts yet

Problem

You are given nn pairwise distinct points and mm lines on the plane.

A line divides the plane into two half-planes. Both of them are closed, which means the line itself belongs to each of the two half-planes. A line is called separating when each of the two half-planes it creates contains at least one of the given points.

For every given line, decide whether it is separating.

Because a point lying exactly on the line belongs to both half-planes, a line that passes through at least one of the points is always separating. In other words, a line fails to be separating only when every point lies strictly on the same side of it, with no point on the line.

Input

The first line contains an integer ZZ (Z=1Z = 1), the number of test cases. Each test case is given as follows.

The first line contains an integer nn (1≤n≤100 0001 \le n \le 100\,000), the number of points. Each of the next nn lines contains two integers xx and yy (1≤x,y≤1091 \le x, y \le 10^9), the coordinates of one point. All points are pairwise distinct.

The next line contains an integer mm (1≤m≤100 0001 \le m \le 100\,000), the number of lines. Each of the next mm lines contains four integers x1x_1, y1y_1, x2x_2, y2y_2 (1≤x1,y1,x2,y2≤1091 \le x_1, y_1, x_2, y_2 \le 10^9), the coordinates of two distinct points that the line passes through.

Output

For each of the mm lines, print TAK (yes) if it is separating, or NIE (no) otherwise. Print each answer on its own line.

Examples3

  1. Example 1

    Input
    1
    4
    10 10
    20 20
    10 20
    20 10
    4
    30 30 31 31
    15 1 15 100
    1 2 2 13
    10 10 11 11
    
    Expected output
    TAK
    TAK
    NIE
    TAK
    
  2. Example 2

    Input
    1
    1
    5 5
    3
    5 5 6 6
    1 1 1 9
    10 1 20 1
    
    Expected output
    TAK
    NIE
    NIE
    
  3. Example 3

    Input
    1
    2
    1 1
    100 100
    4
    50 1 50 100
    1 1 100 100
    200 1 200 100
    1 100 2 100
    
    Expected output
    TAK
    TAK
    NIE
    TAK