You are given a permutation $$$p$$$$$$^{\text{∗}}$$$ of integers from $$$1$$$ to $$$n$$$.
For an arbitrary permutation $$$q$$$ of length $$$n$$$, we say that index $$$j$$$ dominates index $$$i$$$ if and only if all of the following conditions hold:
You are also given an array $$$d$$$ of length $$$n$$$, where $$$d_i$$$ denotes the number of indices that dominate index $$$i$$$.
Your task is to construct a permutation $$$q$$$ of integers from $$$1$$$ to $$$n$$$ such that for every index $$$i$$$ ($$$1 \le i \le n$$$), the number of indices $$$j$$$ that dominate $$$i$$$ is exactly $$$d_i$$$.
If such $$$q$$$ exists, output any valid one. Otherwise, report that it does not exist.
$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 5000$$$).
The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$. It is guaranteed that $$$p$$$ forms a permutation of integers from $$$1$$$ to $$$n$$$.
The third line of each test case contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$0 \le d_i \le n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case:
732 3 11 0 043 4 1 22 1 1 052 3 1 4 52 2 1 1 011053 1 4 2 51 1 1 1 043 4 2 11 1 1 087 6 3 1 2 5 4 81 1 2 2 2 1 1 0
1 2 3-12 1 4 3 512 4 1 3 5-11 2 4 6 5 3 7 8
In the first test case, a valid output is $$$q = [1, 2, 3]$$$:
In the second test case, $$$p = [3, 4, 1, 2]$$$ and $$$d = [2, 1, 1, 0]$$$. Let's look at $$$i=2$$$, where $$$p_2=4$$$. Since there is no index $$$j \gt 2$$$ with $$$p_j \gt p_2$$$, no index can dominate $$$i=2$$$. However, the array $$$d$$$ requires $$$d_2=1$$$, which makes it impossible to construct a valid permutation $$$q$$$. Hence, the answer is -1.
| Name |
|---|


