CSES - Aalto Competitive Programming 2024 - wk4 - Wed - Conurbation
  • Time limit: 2.00 s
  • Memory limit: 512 MB

At the dawn of time, there existed nn towns in southern Finland numbered 1,2,,n1,2,\dots,n. The ii-th town initially had aia_i citizens. Over time, the towns started to spread and merge, eventually forming cities.

You are presented with the history of the towns. The history has mm entries numbered 1,2,,m1,2,\dots,m, the ii-th of which records that towns uiu_i and viv_i merged during year ii and the population of the city they belong to increased by wiw_i.

You are also given qq queries numbered 1,2,,q1,2,\dots,q of the form: xj yjx_j\ y_j - what's the population count of the city town xjx_j belongs to at the end of year yjy_j?

Input

The first line contains three integers nn,mm, and qq. The second line contains nn integers a1,a2,,ana_1,\,a_2,\ldots,\,a_n. The 𝑖𝑖-th of the next mm lines contains three integers uiu_i, v𝑖v_𝑖, and wiw_i. The 𝑖𝑖-th of the next qq lines contains two integers xix_i, and y𝑖y_𝑖.

Output

Print the answers to the queries on a single line.

Constraints

  • 2n1052 \leq n \leq 10^5
  • 1m,q2×1051 \leq m, q \leq 2 \times 10^5
  • 1ai1001 \leq a_i \leq 100
  • 1ui<vin1 \leq u_i < v_i \leq n
  • 1wi10001 \leq w_i \leq 1000
  • (ui,vi)(uj,vj)(u_i, v_i) \neq (u_j, v_j) if iji \neq j
  • 1xjn1 \leq x_j \leq n
  • 1yjm1 \leq y_j \leq m

Example 1

Input:

4 6 5
7 9 8 10 
1 2 9
1 3 2
1 4 3
2 3 3
2 4 7
3 4 2
4 5
2 6
1 1
1 5
1 6

Output:

58 60 25 58 60

Example 2

Input:

10 7 10
6 2 8 8 3 9 6 5 5 9 
2 3 2
2 7 1
3 5 10
5 6 6
5 10 3
6 9 1
6 10 3
5 1
1 2
2 4
6 4
3 2
2 6
3 5
4 2
5 3
3 4

Output:

3 6 47 47 19 65 59 8 32 47