문제
Farmer John is hiring a new herd leader for his cows. To that end, he has interviewed () cows for the position. After interviewing the th candidate, he assigned the candidate an integer "cowmpetency" score ranging from to inclusive () that is correlated with their leadership abilities.
Because he has interviewed so many cows, Farmer John does not remember all of their cowmpetency scores. However, he does remembers () pairs of numbers where cow was the first cow with a strictly greater cowmpetency score than cows through (so ).
Farmer John now tells you the sequence (where means that he has forgotten cow 's cowmpetency score) and the pairs of . Help him determine the lexicographically smallest sequence of cowmpetency scores consistent with this information, or that no such sequence exists! A sequence of scores is lexicographically smaller than another sequence of scores if it assigns a smaller score to the first cow at which the two sequences differ.
Each input contains independent test cases. The sum of across all test cases is guaranteed to not exceed .
입력
The first line contains , the number of independent test cases. Each test case is described as follows: First, a line containing , , and .Next, a line containing the sequence .Finally, lines each containing a pair . It is guaranteed that all within a test case are distinct.
출력
For each test case, output a single line containing the lexicographically smallest sequence of cowmpetency scores consistent with what Farmer John remembers, or if such a sequence does not exist.
예제 입력 1
1
7 3 5
1 0 2 3 0 4 0
1 2
3 4
4 5
예제 출력 1
1 2 2 3 4 4 1
예제 입력 2
5
7 6 10
0 0 0 0 0 0 0
1 2
2 3
3 4
4 5
5 6
6 7
8 4 9
0 0 0 0 1 6 0 6
1 3
6 7
4 7
2 3
2 1 1
0 0
1 2
10 4 10
1 2 0 2 1 5 8 6 0 3
4 7
1 2
5 7
3 7
10 2 8
1 0 0 0 0 5 7 0 0 0
4 6
6 9
예제 출력 2
1 2 3 4 5 6 7
1 1 2 6 1 6 7 6
-1
1 2 5 2 1 5 8 6 1 3
-1
점수
Input 3 satisfies and .Inputs 4-8 satisfy .Inputs 9-12 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인