#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int n, nTest;
int a[111], ret[111];
pair<int, int> b[111];
int main() {
freopen("cubes.in", "r", stdin);
// freopen("cubes.out", "w", stdout);
scanf("%d", &nTest);
for(int test = 1; test <= nTest; test++) {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", a+i);
b[i] = make_pair(i*(n-i+1), -i);
}
sort(a+1, a+1+n, greater<int>());
sort(b+1, b+1+n);
for(int i = 1; i <= n; i++)
ret[-b[i].second] = a[i];
printf("Case %d:\n", test);
for(int i = 1; i <= n; i++) printf("%d ", ret[i]);
if (test < nTest) printf("\n");
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBuLCBuVGVzdDsKaW50IGFbMTExXSwgcmV0WzExMV07CnBhaXI8aW50LCBpbnQ+IGJbMTExXTsKCmludCBtYWluKCkgewogICAgZnJlb3BlbigiY3ViZXMuaW4iLCAiciIsIHN0ZGluKTsKLy8gICAgZnJlb3BlbigiY3ViZXMub3V0IiwgInciLCBzdGRvdXQpOwogICAgc2NhbmYoIiVkIiwgJm5UZXN0KTsKICAgIGZvcihpbnQgdGVzdCA9IDE7IHRlc3QgPD0gblRlc3Q7IHRlc3QrKykgewogICAgICAgIHNjYW5mKCIlZCIsICZuKTsKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgICAgICBzY2FuZigiJWQiLCBhK2kpOwogICAgICAgICAgICBiW2ldID0gbWFrZV9wYWlyKGkqKG4taSsxKSwgLWkpOwogICAgICAgIH0KICAgICAgICBzb3J0KGErMSwgYSsxK24sIGdyZWF0ZXI8aW50PigpKTsKICAgICAgICBzb3J0KGIrMSwgYisxK24pOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSAKICAgICAgICAgICAgcmV0Wy1iW2ldLnNlY29uZF0gPSBhW2ldOwogICAgICAgIHByaW50ZigiQ2FzZSAlZDpcbiIsIHRlc3QpOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSBwcmludGYoIiVkICIsIHJldFtpXSk7CiAgICAgICAgaWYgKHRlc3QgPCBuVGVzdCkgcHJpbnRmKCJcbiIpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=