#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 1e6 + 10;
struct edge {
  int u, v, w, ind;
};
int n, m, comp[N], col[N];
vector<int> nodes[N];
edge e[M];
void init() {
  for (int i = 0; i < (int)(n); i++) {
    comp[i] = i;
    col[i] = 0;
    nodes[i] = vector<int>{i};
  }
}
void merge(int x, int y) {
  int a = comp[x], b = comp[y];
  if (((int)(nodes[a]).size()) < ((int)(nodes[y]).size())) {
    swap(x, y);
    swap(a, b);
  }
  bool inv = col[x] == col[y];
  for (auto u : nodes[b]) {
    nodes[a].push_back(u);
    col[u] ^= inv;
    comp[u] = a;
  }
  nodes[b].clear();
}
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < (int)(m); i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    u--;
    v--;
    e[i] = (edge){u, v, w, i + 1};
  }
  sort(e, e + m, [](edge x, edge y) { return x.w > y.w; });
  while (q--) {
    init();
    int l, r;
    scanf("%d %d", &l, &r);
    int ans = -1;
    for (int i = 0; i < (int)(m); i++)
      if (l <= e[i].ind && e[i].ind <= r) {
        int u = e[i].u, v = e[i].v;
        if (comp[u] == comp[v]) {
          if (col[u] == col[v]) {
            ans = e[i].w;
            break;
          }
        } else
          merge(u, v);
      }
    printf("%d\n", ans);
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve the following problem:

Long 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 wi. 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 li and ri 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, <image>) — 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 ui, vi and wi (1 ≤ ui, vi ≤ n, 0 ≤ wi ≤ 109), denoting the road number i connects cities ui and vi and its length is equal wi. 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 li and ri (1 ≤ li ≤ ri ≤ 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 1e6 + 10;
struct edge {
  int u, v, w, ind;
};
int n, m, comp[N], col[N];
vector<int> nodes[N];
edge e[M];
void init() {
  for (int i = 0; i < (int)(n); i++) {
    comp[i] = i;
    col[i] = 0;
    nodes[i] = vector<int>{i};
  }
}
void merge(int x, int y) {
  int a = comp[x], b = comp[y];
  if (((int)(nodes[a]).size()) < ((int)(nodes[y]).size())) {
    swap(x, y);
    swap(a, b);
  }
  bool inv = col[x] == col[y];
  for (auto u : nodes[b]) {
    nodes[a].push_back(u);
    col[u] ^= inv;
    comp[u] = a;
  }
  nodes[b].clear();
}
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < (int)(m); i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    u--;
    v--;
    e[i] = (edge){u, v, w, i + 1};
  }
  sort(e, e + m, [](edge x, edge y) { return x.w > y.w; });
  while (q--) {
    init();
    int l, r;
    scanf("%d %d", &l, &r);
    int ans = -1;
    for (int i = 0; i < (int)(m); i++)
      if (l <= e[i].ind && e[i].ind <= r) {
        int u = e[i].u, v = e[i].v;
        if (comp[u] == comp[v]) {
          if (col[u] == col[v]) {
            ans = e[i].w;
            break;
          }
        } else
          merge(u, v);
      }
    printf("%d\n", ans);
  }
  return 0;
}

```