Under construction

Still being built. Things may change

Cowmpetency

Time limit2sMemory limit1024 MB

Summary
Fill the forgotten scores so the sequence is lexicographically smallest and each (a, h) pair makes cow h the first to beat cows 1 through a, or print -1.
Level

Medium6 of 10

Topics
Array, Greedy, Implementation
Solved
No attempts yet

Problem

Farmer John is hiring a new herd leader for his cows. To that end, he has interviewed NN (2≤N≤1052 \leq N \leq 10^5) cows for the position. After interviewing the iith candidate, he assigned the candidate an integer "cowmpetency" score cic_i ranging from 11 to CC inclusive (1≤C≤1091 \leq C \leq 10^9) 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 remember QQ (1≤Q<N1 \leq Q < N) pairs of numbers (aj,hj)(a_j, h_j) where cow hjh_j was the first cow with a strictly greater cowmpetency score than cows 11 through aja_j (so 1≤aj<hj≤N1 \leq a_j < h_j \leq N).

Farmer John now tells you the sequence c1,…,cNc_1, \dots, c_N (where ci=0c_i = 0 means that he has forgotten cow ii's cowmpetency score) and the QQ pairs of (aj,hj)(a_j, h_j). 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 if it assigns a smaller score to the first cow at which the two sequences differ.

Input

The first line contains TT, the number of independent test cases (1≤T≤201 \leq T \leq 20). Each test case is described as follows:

  1. A line containing NN, QQ, and CC.
  2. A line containing the sequence c1,…,cNc_1, \dots, c_N (0≤ci≤C0 \leq c_i \leq C).
  3. QQ lines each containing a pair (aj,hj)(a_j, h_j). All aja_j within a test case are distinct.

The sum of NN across all test cases does not exceed 3⋅1053 \cdot 10^5.

Output

For each test case, output a single line containing the lexicographically smallest sequence of cowmpetency scores consistent with the information, or −1-1 if no such sequence exists.

Examples2

  1. Example 1

    Input
    1
    7 3 5
    1 0 2 3 0 4 0
    1 2
    3 4
    4 5
    
    Expected output
    1 2 2 3 4 4 1
    
  2. Example 2

    Input
    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
    
    Expected output
    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