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 m, steal items whose values sum to exactly k, and escape, with the whole heist taking s units of time.
Each item i has a value ci, a moment ai when it is left in the cloakroom, and a moment bi 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 (ai≤m) and its owner does not come back for it at any moment up to and including the escape time m+s (that is, bi>m+s). If any owner returns for their item at some moment no later than m+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 k. If exactly k 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.
The first line contains the number of items n (1≤n≤1000).
Each of the next n lines describes one item with three integers ci, ai, bi (1≤ci≤1000, 1≤ai<bi≤109): 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 p (1≤p≤106).
Each of the next p lines describes one plan with three integers mj, kj, sj (1≤mj≤109, 1≤kj≤105, 0≤sj≤109): the moment the thieves enter, the total value they want to steal, and the time the heist takes.
For each plan, print TAK (Polish for yes) on its own line if it is feasible, that is, if items summing to exactly kj 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.