#include <cstdio>
#include <cstdlib>
const int N = 100, TRY = 100000;
int n, h[N], obs[N];
bool place() {
double tang, t;
int i, j, best;
for (i = 0; i < n; ++i)
h[i] = rand();
for (i = 0; i < n - 1; ++i) {
tang = -1e18; // Тангенс угла близкого к -Pi/2
best = i + 1; // Тут будет номер горы с максимальным тангенсом.
for (j = i + 1; j < n; ++j) { // Начинаем с следующей горы.
t = double(h[j] - h[i]) / double(j - i);
if (tang < t) {
best = j;
tang = t;
}
}
// Если гора с максимальным тангенсом
// не совпадает с указанной в условии...
if (best != obs[i])
return false;
}
return true;
}
int main() {
/*/
freopen("C:\\Users\\anonymous\\Downloads\\C-small-practice.in", "r", stdin);
freopen("C:\\Users\\anonymous\\Desktop\\out.txt", "w", stdout);
/**/
int t, it, i;
scanf("%d", &t);
for (it = 1; it <= t; ++it) {
scanf("%d", &n);
for (i = 0; i < n - 1; ++i) {
scanf("%d", &obs[i]); // Читаю обозримую вершину.
--obs[i]; // Привожу к нумерации с нуля.
}
for (i = 0; i < TRY; ++i) // Делаю TRY попыток расставить высоты.
if (place())
break;
printf("Case #%d:", it);
if (i == TRY) {
printf(" Impossible");
} else {
for (i = 0; i < n; ++i)
printf(" %d", h[i]);
}
putchar('\n');
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdGRsaWI+CiAKY29uc3QgaW50IE4gPSAxMDAsIFRSWSA9IDEwMDAwMDsKIAppbnQgbiwgaFtOXSwgb2JzW05dOwogCmJvb2wgcGxhY2UoKSB7Cglkb3VibGUgdGFuZywgdDsKCWludCBpLCBqLCBiZXN0OwoJZm9yIChpID0gMDsgaSA8IG47ICsraSkKCQloW2ldID0gcmFuZCgpOwoJZm9yIChpID0gMDsgaSA8IG4gLSAxOyArK2kpIHsKCQl0YW5nID0gLTFlMTg7IC8vINCi0LDQvdCz0LXQvdGBINGD0LPQu9CwINCx0LvQuNC30LrQvtCz0L4g0LogLVBpLzIKCQliZXN0ID0gaSArIDE7IC8v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