Twibet (Small)

Starting from each monk in turn, count how many monks hear a whisper that spreads from a monk to all direct and indirect followers.

Easy3GraphDFSInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

The holy country of Twibet has NN monks. Each monk carries a distinct number from 11 to NN, and for religious reasons the monks use no names. They walk slowly around Twibet all the time, and each monk follows exactly one other monk.

Most days everyone stays silent. On day KK, monk KK stops, turns around and whispers the 140 Words of Wisdom. The whisper is quiet, so only the monks who follow him directly can hear it. Each monk who hears the words stops, turns around and whispers the same words to his own followers. The chain continues this way: every monk who has just heard the words and has not whispered them yet stops and whispers to his followers.

Once every monk who could hear the words has whispered them, they all turn back around and keep walking as usual. The next day the same thing happens, this time starting with a different monk.

For every KK between 11 and NN, count how many monks whisper the 140 Words of Wisdom on day KK.

Input

The first line contains the number of test cases TT. TT test cases follow.

The first line of each test case contains an integer NN. The second line contains NN space separated integers F1,F2,,FNF_1, F_2, \dots, F_N. Monk ii follows monk FiF_i.

Limits

  • 1T1001 \le T \le 100
  • 2N102 \le N \le 10
  • 1FiN1 \le F_i \le N, FiiF_i \ne i (no monk follows himself)

Output

For each test case, output one line in the form Case #x:, where xx is the test case number starting from 11. Then output NN lines. The first line holds the number of monks who whisper the words on day 1, the next line the number on day 2, and so on through day NN.

Explanation

In the first test case of the example, the 3 monks walk in a single circle. Whoever whispers first, his follower whispers next and the remaining monk whispers after that, so all 3 monks whisper on each of the 3 days.

In the second test case, monk 1 follows monk 2, monk 2 follows monk 3, monk 3 follows monk 2, and monk 4 follows monk 1. On day 1 monk 1 whispers first and monk 4 hears him and whispers next, while monks 2 and 3 hear nothing that day. On day 2 monk 2 whispers first, monks 1 and 3 hear him and whisper, and finally monk 4 hears monk 1 and whispers last. On day 3 the monks whisper in the order 3, 2, 1, 4. On day 4 monk 4 whispers and nobody hears him.