The peak that looks highest

Given each peak's apparent highest peak ahead, build heights with the stated rule and print Impossible when they disagree with the memory.

Medium4GeometryImplementationNo attempts yetTime limit5sMemory limit512 MB

Problem

You are walking along a mountain range. There is one peak every kilometre and no peaks in between. On each peak you lie down to rest, look ahead, and one of the peaks in front of you looks like the highest one. The peak that looks highest is not always the highest one. There are two reasons. A higher peak can be hidden behind a nearer and lower peak, and when you look downhill a distant peak can look higher than a close one.

To be precise, peak BB looks like the highest one from peak AA when all three of the following hold. BB is further along the road than AA. Every peak between AA and BB is strictly below the line joining AA and BB. Every peak past BB is on that line or below it.

You do not know the height of any peak, but your memory is good. You have stood on all of them and you remember which peak looked highest from each one. Invent one set of heights that agrees with that memory. You were lying down while looking, so treat every line of sight as starting at ground level on its peak.

In the picture the fourth peak looks like the highest one from the first peak and from the third peak. Lying on the second peak you cannot see the fourth peak, because the third one hides it, and the third peak looks like the highest one.

Input

The first line contains the number of test cases TT. Each test case takes two lines. The first line contains NN, the number of peaks in the range. Your trip started on peak 1 and went forward to peak NN. The second line contains N1N-1 numbers x1,x2,,xN1x_1, x_2, \dots, x_{N-1}, where xix_i is the index of the peak that looked highest from peak ii. Peak NN is the last one, so no peak is visible ahead of it and no number is given for it.

Output

For each test case print one line in the form Case #n: y1 y2 ... yN, where nn is the test case number counted from 1 and yiy_i is the height of peak ii. If no set of heights agrees with the memory, print Case #n: Impossible instead.

Several different sets of heights can agree with the same memory, so print only the heights that the following rule fixes.

  1. For each ii from 11 to N1N-1, let rir_i be the number of indices jj with jij \le i and xj=xix_j = x_i. So rir_i is the position of peak ii, counted from the left, among the peaks whose highest looking peak is xix_i.
  2. Set tN=0t_N = 0, and for ii from N1N-1 down to 11 set ti=txi+rit_i = t_{x_i} + r_i.
  3. Set hN=0h_N = 0, and for ii from N1N-1 down to 11 set hi=hxiti(xii)h_i = h_{x_i} - t_i (x_i - i).
  4. Let mm be the smallest of h1,h2,,hNh_1, h_2, \dots, h_N and print yi=himy_i = h_i - m.

Whenever any set of heights agrees with the memory, the heights this rule builds agree with it too. Every value the rule prints is an integer between 00 and (N1)2(N-1)^2.

Constraints

  • 1T301 \le T \le 30
  • i<xiNi < x_i \le N
  • 2N20002 \le N \le 2000