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
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const long long inf64 = 1ll * inf * inf;
struct DSU {
  int n;
  vector<int> par, color, h;
  DSU() { n = 0; }
  DSU(int nn) {
    n = nn;
    par.resize(n + 1);
    color.resize(n + 1);
    h.resize(n + 1);
    for (int i = 1; i <= n; i++) {
      par[i] = i;
      color[i] = h[i] = 0;
    }
  }
  int find(int x) {
    if (x == par[x])
      return x;
    else {
      int t = find(par[x]);
      color[x] ^= color[par[x]];
      return par[x] = t;
    }
  }
  int parity(int x) {
    find(x);
    return color[x];
  }
  int add_edge(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (px == py) {
      if (parity(x) == parity(y))
        return 2;
      else
        return 0;
    }
    if (h[px] < h[py]) {
      swap(px, py);
      swap(x, y);
    }
    color[py] ^= (parity(x) ^ parity(y) ^ 1);
    if (h[py] == h[px]) h[px]++;
    par[py] = px;
    return 1;
  }
};
int n, m, q;
struct edge {
  int u, v, id, w;
  static int EdgeCount;
  edge() { u = v = id = w = 0; }
  void read() {
    scanf("%d %d %d", &u, &v, &w);
    id = EdgeCount++;
  }
  void print() { printf("#%d {%d %d} [%d]\n", id, u, v, w); }
  bool operator<(const edge& b) const {
    return make_tuple(w, u, v, id) < make_tuple(b.w, b.u, b.v, b.id);
  }
  bool operator>(const edge& b) const {
    return make_tuple(w, u, v, id) > make_tuple(b.w, b.u, b.v, b.id);
  }
  bool operator==(const edge& b) const {
    return make_tuple(w, u, v, id) == make_tuple(b.w, b.u, b.v, b.id);
  }
};
int edge ::EdgeCount = 1;
int RESULT;
void upd(vector<edge>& l) {
  vector<edge> res;
  DSU dsu(n);
  RESULT = -1;
  for (auto _e : l) {
    int type = dsu.add_edge(_e.u, _e.v);
    if (type) res.push_back(_e);
    if (type == 2) {
      RESULT = _e.w;
      break;
    }
  }
  l = res;
}
vector<edge> merge(const vector<edge>& l, const vector<edge>& r) {
  int left_size = (int)l.size();
  int right_size = (int)r.size();
  int left_cur = 0, right_cur = 0;
  vector<edge> res;
  while (left_cur < left_size && right_cur < right_size) {
    if (l[left_cur] > r[right_cur])
      res.push_back(l[left_cur++]);
    else
      res.push_back(r[right_cur++]);
  }
  while (left_cur < left_size) res.push_back(l[left_cur++]);
  while (right_cur < right_size) res.push_back(r[right_cur++]);
  upd(res);
  return res;
}
vector<vector<edge> > st;
vector<edge> e;
void build(int v, int tl, int tr) {
  if (tl == tr) {
    st[v].push_back(e[tl]);
  } else {
    int tm = (tl + tr) / 2;
    build(v << 1, tl, tm);
    build(v << 1 | 1, tm + 1, tr);
    st[v] = merge(st[v << 1], st[v << 1 | 1]);
  }
}
vector<edge> get(int v, int tl, int tr, int l, int r) {
  if (l <= tl && tr <= r)
    return st[v];
  else {
    int tm = (tl + tr) / 2;
    if (l <= tm) {
      if (r > tm)
        return merge(get(v << 1, tl, tm, l, r),
                     get(v << 1 | 1, tm + 1, tr, l, r));
      else
        return get(v << 1, tl, tm, l, r);
    } else
      return get(v << 1 | 1, tm + 1, tr, l, r);
  }
}
bool solve() {
  scanf("%d %d %d", &n, &m, &q);
  e.resize(m + 1);
  for (int i = 1; i <= m; i++) e[i].read();
  st.resize(4 * m);
  build(1, 1, m);
  for (int l, r; q > 0; q--) {
    scanf("%d %d", &l, &r);
    auto tmp = get(1, 1, m, l, r);
    upd(tmp);
    printf("%d\n", RESULT);
  }
  return true;
}
int main() {
  solve();
  return 0;
}
