Cloakroom

No attempts yetTime limit2sMemory limit128 MB

Problem

Every year the wealthy citizens of Byteotia gather for a grand reunion. Coats, jackets, umbrellas and other belongings are not carried into the banquet hall; guests leave them in the cloakroom and pick them up on their way out.

A gang of thieves is planning to rob the cloakroom. A single plan has the following form. The thieves break in at time mm, steal items whose values sum to exactly kk, and escape, with the whole heist taking ss units of time.

Each item ii has a value cic_i, a moment aia_i when it is left in the cloakroom, and a moment bib_i when its owner comes back for it. An item can be stolen only if it has already been checked in by the time the thieves enter (aima_i \le m) and its owner does not come back for it at any moment up to and including the escape time m+sm + s (that is, bi>m+sb_i > m + s). If any owner returns for their item at some moment no later than m+sm + s, the theft is discovered and the plan fails.

A plan is feasible if it is possible to pick only such items so that their values sum to exactly kk. If exactly kk cannot be formed, the plan is infeasible. An item left in the cloakroom at the very moment the break-in starts may already be stolen. Decide, for each plan, whether it is feasible.

Input

The first line contains the number of items nn (1n10001 \le n \le 1000).

Each of the next nn lines describes one item with three integers cic_i, aia_i, bib_i (1ci10001 \le c_i \le 1000, 1ai<bi1091 \le a_i < b_i \le 10^9): the item's value, the moment it is left in the cloakroom, and the moment its owner retrieves it.

The next line contains the number of plans pp (1p1061 \le p \le 10^6).

Each of the next pp lines describes one plan with three integers mjm_j, kjk_j, sjs_j (1mj1091 \le m_j \le 10^9, 1kj1051 \le k_j \le 10^5, 0sj1090 \le s_j \le 10^9): the moment the thieves enter, the total value they want to steal, and the time the heist takes.

Output

For each plan, print TAK (Polish for yes) on its own line if it is feasible, that is, if items summing to exactly kjk_j can be stolen and the thieves can escape before anyone returns for their belongings; otherwise print NIE (Polish for no). Process the plans in the order given in the input.