Tea

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Bytemommy whole-heartedly loves her Bytekids. However she is kinda forgetful, so instead of giving their proper names, she numbered them with consecutive integers from 11 to nn. Everyday she prepares a tea for each of her Bytekids in their favourite cups. One peculiar property of all tea cups in their home is that they have infinite capacity, even though they take finite space only. However, this is for our simplicity only. Bytekid number ii prefers to drink exactly l_il\_i bitres of tea everyday. However, amount of tea is not their only requirement --- its temperature has to be properly adjusted as well. Bytekid number ii would like its tea to have exactly b_ib\_i Bytesius degrees.

Unfortunately, one day scatterbrained Bytemommy messed up teas temperatures and temperature of tea in ii-th cup was exactly a_ia\_i Bytesius degrees, instead of b_ib\_i (however ii-th kid still got l_il\_i bitres in its cup). Nothing is lost yet --- Bytekids are very clever and using some auxiliary cups started to mix up their teas trying to get cups with appropriate amounts and temperatures of teas. You need to determine whether it is possible for Bytekids to reach their goal, that is to get nn teas so that ii-th tea has exactly l_il\_i bitres and b_ib\_i Bytesius degrees.

Formally, Bytekids are allowed to perform following steps arbitrarily many times:

  • Partitioning the tea. Given a cup with aa bitres of tea with temperature tt, create two cups of tea with xx and axa-x bitres of tea with temperature tt for some arbitrary real value of xx such that 0\<x\<a0\<x\<a (initial cup of tea will no longer exist, obviously).
  • Mixing the tea. Given two cups of tea with aa and bb bitres of tea with temperatures t_at\_a and t_bt\_b, respectively, create one cup of tea with a+ba+b bitres of tea with temperature at_a+bt_ba+b,\frac{a \cdot t\_a + b \cdot t\_b}{a + b}, that is, the weighted mean of initial temperatures (again, initial two cups of tea will no longer exist).

입력

The first line of input contains one integer tt (1t100,0001 \le t \le 100\\,000) denoting number of testcases.

Description of each testcase starts with a line containing one integer nn (1n100,0001 \le n \le 100\\,000) denoting number of Bytekids. Following nn lines describe Bytekids: ii-th of them contains three integers l_il\_i, a_ia\_i and b_ib\_i (1l_i,a_i,b_i1,000,0001 \le l\_i, a\_i, b\_i \le 1\\,000\\,000) denoting amount of tea in ii-th cup in bitres (both initial and required final one) and initial and required temperature of that tea, respectively.

Sum of values of nn over all testcases will not exceed 1,000,0001\\,000\\,000.

출력

You need to print tt lines, ii-th of them should contain a word TAK if it is possible for Bytekids to reach their goal in ii-th testcase, or NIE otherwise.

힌트

Denote cups of tea as pair of numbers. Pair (l,t)(l, t) denotes cup with ll bitres of tea with temperature tt Bytesius degrees.

In the first testcase Bytekids have cups (2,1)(2, 1) and (2,5)(2, 5). Using operation of partitioning the tea they can get cups (12,1)(\frac12, 1), (32,1)(\frac32, 1), (12,5)(\frac12, 5) and (32,5)(\frac32, 5).

Then, by mixing up cups (12,1)(\frac12, 1) and (32,5)(\frac32, 5), they get 12+32=2\tfrac12 + \tfrac32 = 2 with temperature 

121+32512+32=4,\frac{\frac12 \cdot 1 + \frac32 \cdot 5}{\frac12 + \frac32} = 4, that is --- cup (2,4)(2,4). Similarly, by mixing cup (32,1)(\frac32, 1) with (12,5)(\frac12, 5), they get (2,2)(2, 2). In the end, Bytekids will have two cups with appropriate amounts and temperatures of tea.

In the second testcase both teas are too hot. We can't do much here.

However, in the third testcase it is sufficient for Bytekids to swap their cups.