Ace in the Hole

Given Ben's examination order, restore the lexicographically greatest deck with no decreasing triple that makes his optimal search follow it.

Hard9Game theoryGreedySimulationCombinatoricsNo attempts yetTime limit60sMemory limit512 MB

Problem

Amy has a deck of NN cards whose values are 1 through NN, one value per card. She lays the cards in a row so that the sequence of values has no decreasing subsequence of length 3. For example, 1, 5, 4, 6, 3, 2 breaks the rule, because 5, 3, 2 is decreasing.

Amy gives the deck to Ben. Ben knows the deck has no decreasing subsequence of length 3, but he does not know the exact arrangement. He wants to find the card with value 1. He picks one card, looks at its value, and repeats until he finds the card with value 1. At each step Ben considers every arrangement that agrees with the values he has already seen, then picks a card that minimizes the worst-case number of cards he still has to examine.

Ben says he was unlucky and examined all NN cards before he found the card with value 1. Given the order in which he examined the cards, find the value of each card. If several arrangements are possible, choose the lexicographically greatest one.

A deck AA is lexicographically greater than a deck BB when, at the first position where the two differ, the value in AA is greater than the value in BB.

Input

The first line contains the number of test cases TT. Each test case begins with a line containing one integer NN, the number of cards in the deck. The next line contains NN integers separated by single spaces, describing the order in which Ben examined the deck. The ii-th integer is the position of the card he examined ii-th, and positions are counted from 1.

Output

For each test case, print one line in the form "Case #x: y", where xx is the test case number starting from 1 and yy is the values of the cards from the first to the NN-th, separated by single spaces.

Constraints

  • 1T1001 \le T \le 100
  • 1N3001 \le N \le 300
  • The examination order is a permutation in which each position from 1 to NN appears exactly once.
  • For the given examination order, at least one deck meets every condition of the problem, including the condition that Ben had to examine all NN cards.