Persuading the Advisers

No attempts yetTime limit1sMemory limit256 MB

Problem

Bajtazar wants to build a racetrack in Byteotia. Bajtymon competes for the same money and would rather build a ski jump. Both projects are expensive, so the two men ask the king of Byteotia for funding.

The king funds exactly one of them, the racetrack or the ski jump. Before he decides he asks the Chief Adviser, who heads the hierarchy of royal advisers. An adviser is one of two kinds. An expert gives a recommendation on his own, and every other adviser heads a team of advisers. A team head recommends the option that the majority of his team members support. Every team has an odd number of members, so the majority is always settled. The final recommendation therefore depends only on what the experts support, an expert being an adviser who heads no team. Every adviser other than the Chief Adviser has exactly one superior.

Bajtazar and Bajtymon do not wait idly. They persuade the experts. Persuading one expert takes exactly one day, and a persuaded expert never changes his mind. Some experts already hold an opinion at the start and will not change it.

Every day at dawn Bajtazar picks one undecided expert and visits him to win him over to the racetrack. Bajtymon does not get up that early, so later the same day he picks one of the remaining undecided experts and wins him over to the ski jump. That is why he loses the chance to persuade the expert Bajtazar visited that day. If no undecided expert is left that day, Bajtymon persuades nobody. The two act this way until every expert holds an opinion. Both of them know the hierarchy of advisers.

Decide whether Bajtazar can plan his persuading so that the Chief Adviser recommends building the racetrack, whatever Bajtymon does.

Input

The first line contains one integer nn (2n10002 \le n \le 1000), the number of advisers. The advisers are numbered from 11 to nn, and adviser 11 is the Chief Adviser. The ii-th of the next nn lines describes adviser ii. The line starts with an integer cic_i (2cin-2 \le c_i \le n). If ci0c_i \le 0, then adviser ii is an expert and the line contains only cic_i. The values 2-2, 1-1 and 00 mean that he is for the racetrack, for the ski jump, and undecided, respectively. If ci1c_i \ge 1, then cic_i is odd and adviser ii heads a team of cic_i members whose numbers follow on the rest of the line. Every adviser with a number greater than 11 belongs to exactly one team.

Output

If Bajtazar cannot persuade the experts in a way that makes the Chief Adviser recommend the racetrack, print one line with the word NIE. Otherwise print two lines. The first line contains the word TAK and an integer dd. Here dd counts the ways Bajtazar can choose the expert to persuade on the first day such that, playing optimally on the later days, he is still sure of the favorable recommendation. The second line contains the numbers of those dd experts in increasing order. If every expert already holds an opinion at the start and the recommendation favors Bajtazar, print d=0d = 0 and leave the second line empty.