Term Project
InterviewTime limit3sMemory limit256 MB
Each student picks exactly one partner, only directed cycles form teams, so count the students outside all cycles.
Problem
Every student who signed up for the 'Problem Solving' course this fall term has to carry out a term project. There is no limit on how many students a team may have. All of the students can even belong to the same team, leaving a single team. To form the teams, every student picks one student to work with. Only one pick is allowed. A student who wants to work alone may pick themselves.
Students form one team in exactly two situations: and picked , or picked , picked , ..., picked , and picked .
For example, suppose a class has 7 students numbered 1 through 7 and the picks came out like this.
With these picks, (3) and (4, 7, 6) form teams. Students 1, 2, and 5 belong to no team.
Given the result of the picks, write a program that counts the students who belong to no project team.
Input
The first line contains the number of test cases . The first line of each test case contains the number of students (). The second line lists the number that each student picked, in order from student to student . Students are numbered through .
Output
For each test case, print on one line the number of students who ended up on no project team.