CF2185D.OutOfMemoryError

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

OutOfMemoryError

Bessie has an array of nn integers a1,a2,,ana_1, a_2, \ldots, a_n. Bessie performs mm operations on the array. The ii-th operation sets abi=abi+cia_{b_i} = a_{b_i} + c_i.

Unfortunately, due to rising RAM costs, Bessie's computer has limited memory, and whenever any element of the array is greater than hh, her computer crashes, and every element in the array is reset to its original value.

After all operations have been performed, output the array aa.

Input

The first line of the input contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains three integers n,m,hn, m, h (1n,m21051 \le n, m \le 2 \cdot 10^5, 1h1091 \leq h \leq 10^9) — the length of array aa, the number of operations performed, and the maximum value that Bessie's computer can store without crashing.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0aih0 \le a_i \le h) — the array aa.

The next mm lines contain two integers bi,cib_i, c_i (1bin1 \leq b_i \leq n, 0ci1090 \leq c_i \leq 10^9) — the operations that Bessie performs on the array.

It is guaranteed that the sum of nn and the sum of mm over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output the array aa after all operations have been performed.

Note

For the first test case, the array aa is changed as follows:

  • Before all operations, a=[1,2,1]a = [1, 2, 1].
  • After the first operation, a=[5,2,1]a = [5, 2, 1].
  • After the second operation, a=[5,6,1]a = [5, 6, 1], but since 6>h6 \gt h, the computer crashes, and a=[1,2,1]a = [1, 2, 1].
  • After the third operation, a=[1,2,4]a = [1, 2, 4].
  • After the fourth operation, a=[1,2,4]a = [1, 2, 4].

For the third test case, each operation causes the computer to crash, so a=[1,0,0,0]a = [1, 0, 0, 0].

Samples

3
3 4 5
1 2 1
1 4
2 4
3 3
2 0
5 3 1
1 1 1 1 1
1 1
1 1
2 1
4 4 1
1 0 0 0
1 1
4 4
3 3
4 4
1 2 4 
1 1 1 1 1 
1 0 0 0 

在线编程 IDE

建议全屏模式获得最佳体验