Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Dividing Kingdom II

time limit per test

6 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputLong time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.

The great kingdom consisted of *n* cities numbered from 1 to *n* and *m* bidirectional roads between these cities, numbered from 1 to *m*. The *i*-th road had length equal to *w* _{ i}. The Great Arya and Pari The Great were discussing about destructing some prefix (all road with numbers less than some *x*) and suffix (all roads with numbers greater than some *x*) of the roads so there will remain only the roads with numbers *l*, *l* + 1, ..., *r* - 1 and *r*.

After that they will divide the great kingdom into two pieces (with each city belonging to exactly one piece) such that the hardness of the division is minimized. The hardness of a division is the maximum length of a road such that its both endpoints are in the same piece of the kingdom. In case there is no such road, the hardness of the division is considered to be equal to - 1.

Historians found the map of the great kingdom, and they have *q* guesses about the *l* and *r* chosen by those great rulers. Given these data, for each guess *l* _{ i} and *r* _{ i} print the minimum possible hardness of the division of the kingdom.

Input

The first line of the input contains three integers *n*, *m* and *q* (1 ≤ *n*, *q* ≤ 1000, ) — the number of cities and roads in the great kingdom, and the number of guesses, respectively.

The *i*-th line of the following *m* lines contains three integers *u* _{ i}, *v* _{ i} and *w* _{ i} (1 ≤ *u* _{ i}, *v* _{ i} ≤ *n*, 0 ≤ *w* _{ i} ≤ 10^{9}), denoting the road number *i* connects cities *u* _{ i} and *v* _{ i} and its length is equal *w* _{ i}. It's guaranteed that no road connects the city to itself and no pair of cities is connected by more than one road.

Each of the next *q* lines contains a pair of integers *l* _{ i} and *r* _{ i} (1 ≤ *l* _{ i} ≤ *r* _{ i} ≤ *m*) — a guess from the historians about the remaining roads in the kingdom.

Output

For each guess print the minimum possible hardness of the division in described scenario.

Example

Input

5 6 5

5 4 86

5 1 0

1 3 38

2 1 33

2 4 28

2 3 40

3 5

2 6

1 3

2 3

1 6

Output

-1

33

-1

-1

33

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/05/2020 21:10:08 (h3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|