This page is still under construction.

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

Never Say Never

Time limit2sMemory limit128 MB

Summary
Decide whether two employees employed at the same moment ever have equal linear effectiveness values.
Level

Medium7 of 10

Topics
Sorting, Intervals, Geometry
Solved
No attempts yet

Problem

"How on earth am I supposed to set my employees' salaries?" wondered director Karierowitch. "I want everyone paid in proportion to their effectiveness. But effectiveness keeps changing, and surely I will never have two employees with exactly the same effectiveness at the same time."

Many years have passed since then. In total, NN employees have worked at the company over its history. Employee ii is described by four integers sis_i, eie_i, aia_i, bib_i: the employee was hired at time sis_i, left the company (or the company let them go) at time eie_i, and at any moment tt their effectiveness equals ai⋅t+bia_i \cdot t + b_i.

Determine whether there was ever a moment in the company's history at which two employees who were both employed at that moment had exactly the same effectiveness.

  • aia_i may be negative.
  • Effectiveness may be negative (the employee is harming the company instead of generating profit).
  • Every employment interval [si,ei][s_i, e_i] is closed at both ends, and you must consider every real-valued moment tt, not only integer ones.

Input

The first line contains an integer ZZ (1≤Z≤101 \le Z \le 10), the number of test sets. The test sets follow.

The first line of each test set contains an integer NN (1≤N≤1051 \le N \le 10^5), the number of employees in the company's history. Each of the next NN lines contains four space-separated integers sis_i, eie_i, aia_i, bib_i, where 0≤si,ei≤1060 \le s_i, e_i \le 10^6 and −106≤ai,bi≤106-10^6 \le a_i, b_i \le 10^6.

Output

For each test set, print on its own line "TAK" if there exists a moment at which some pair of simultaneously employed employees had the same effectiveness, and "NIE" otherwise.

Examples3

  1. Example 1

    Input
    3
    2
    0 5 0 3
    0 5 0 2
    2
    0 5 0 3
    0 5 0 3
    2
    0 2 1 0
    0 2 -1 2
    
    Expected output
    NIE
    TAK
    TAK
    
  2. Example 2

    Input
    1
    2
    0 10 1 0
    0 10 -1 6
    
    Expected output
    TAK
    
  3. Example 3

    Input
    1
    2
    0 5 1 0
    0 5 2 -10
    
    Expected output
    NIE