Problem: Baldman is a warp master. He possesses a unique ability — creating wormholes! Given two positions in space, Baldman can make a wormhole which makes it possible to move between them in both directions. Unfortunately, such operation isn't free for Baldman: each created wormhole makes him lose plenty of hair from his head.

Because of such extraordinary abilities, Baldman has caught the military's attention. He has been charged with a special task. But first things first.

The military base consists of several underground objects, some of which are connected with bidirectional tunnels. There necessarily exists a path through the tunnel system between each pair of objects. Additionally, exactly two objects are connected with surface. For the purposes of security, a patrol inspects the tunnel system every day: he enters one of the objects which are connected with surface, walks the base passing each tunnel at least once and leaves through one of the objects connected with surface. He can enter and leave either through the same object, or through different objects. The military management noticed that the patrol visits some of the tunnels multiple times and decided to optimize the process. Now they are faced with a problem: a system of wormholes needs to be made to allow of a patrolling which passes each tunnel exactly once. At the same time a patrol is allowed to pass each wormhole any number of times.

This is where Baldman comes to operation: he is the one to plan and build the system of the wormholes. Unfortunately for him, because of strict confidentiality the military can't tell him the arrangement of tunnels. Instead, they insist that his system of portals solves the problem for any arrangement of tunnels which satisfies the given condition. Nevertheless, Baldman has some information: he knows which pairs of objects he can potentially connect and how much it would cost him (in hair). Moreover, tomorrow he will be told which objects (exactly two) are connected with surface. Of course, our hero decided not to waste any time and calculate the minimal cost of getting the job done for some pairs of objects (which he finds likely to be the ones connected with surface). Help Baldman!

Input

First line of the input contains a single natural number n (2 ≤ n ≤ 100000) — the number of objects on the military base. The second line — one number m (1 ≤ m ≤ 200000) — the number of the wormholes Baldman can make. The following m lines describe the wormholes: each line contains three integer numbers a, b, c (1 ≤ a, b ≤ n, 1 ≤ c ≤ 100000) — the numbers of objects which can be connected and the number of hair Baldman has to spend to make this wormhole.

The next line contains one natural number q (1 ≤ q ≤ 100000) — the number of queries. Finally, the last q lines contain a description of one query each — a pair of numbers of different objects ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). There could be more than one wormhole between a pair of objects.

Output

Your program should output q lines, one for each query. The i-th line should contain a single integer number — the answer for i-th query: the minimum cost (in hair) of a system of wormholes allowing the optimal patrol for any system of tunnels (satisfying the given conditions) if ai and bi are the two objects connected with surface, or "-1" if such system of wormholes cannot be made.

Examples

Input

2
1
1 2 3
1
1 2


Output

0


Input

3
1
1 2 3
2
1 2
1 3


Output

-1
3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct kraw {
  int a, c;
};
struct kraw2 {
  int a, b, c, nr;
};
bool por(kraw2 a, kraw2 b) {
  if (a.c < b.c) return true;
  if (a.c > b.c) return false;
  if (a.nr < b.nr) return true;
  return false;
}
vector<int> f;
int nry = 0;
void dfs(int akt, int pop, vector<vector<kraw> >& G, vector<int>& oj,
         vector<int>& wlk, vector<int>& nr, vector<int>& odl) {
  oj[akt] = pop;
  nr[akt] = nry;
  ++nry;
  for (int i = 0; i < G[akt].size(); ++i) {
    if (G[akt][i].a != pop) {
      odl[G[akt][i].a] = odl[akt] + 1;
      dfs(G[akt][i].a, akt, G, oj, wlk, nr, odl);
    }
  }
  wlk[akt] = 1;
  for (int i = 0; i < G[akt].size(); ++i)
    if (G[akt][i].a != pop) wlk[akt] += wlk[G[akt][i].a];
}
bool Parent(int a, int b, vector<int>& nr, vector<int>& wlk) {
  if (nr[b] >= nr[a] && nr[b] <= nr[a] + wlk[a] - 1) return true;
  return false;
}
int LCA(vector<vector<int> >& P, int a, int b, vector<int>& nr,
        vector<int>& wlk) {
  if (Parent(a, b, nr, wlk)) return a;
  if (Parent(b, a, nr, wlk)) return b;
  for (int i = 16; i >= 0; --i)
    if (!Parent(P[i][a], b, nr, wlk)) a = P[i][a];
  return P[0][a];
}
int Daj(int a, int odl, vector<vector<int> >& maxy, vector<vector<int> >& P) {
  int odp = 0;
  for (int i = 16; i >= 0; --i) {
    if (odl >= (1 << i)) {
      odp = max(odp, maxy[i][a]);
      a = P[i][a];
      odl -= (1 << i);
    }
  }
  return odp;
}
void Stworz(int n) {
  for (int i = 0; i < n; ++i) f.push_back(i);
}
int Find(int a) {
  if (f[a] == a) return a;
  int fa = Find(f[a]);
  f[a] = fa;
  return fa;
}
void Union(int a, int b) {
  int fa = Find(a);
  int fb = Find(b);
  f[fb] = fa;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  Stworz(n);
  vector<vector<kraw> > G(n);
  int m;
  cin >> m;
  vector<kraw2> K(m);
  for (int i = 0; i < m; ++i) {
    cin >> K[i].a >> K[i].b >> K[i].c;
    K[i].nr = i;
    --K[i].a;
    --K[i].b;
  }
  sort(K.begin(), K.end(), por);
  long long mst = 0, il_kraw = 0;
  for (int i = 0; i < m; ++i) {
    int a = K[i].a, b = K[i].b, c = K[i].c;
    if (Find(a) != Find(b)) {
      Union(a, b);
      mst += c;
      ++il_kraw;
      G[a].push_back({b, c});
      G[b].push_back({a, c});
    }
  }
  int q;
  cin >> q;
  vector<int> a(q), b(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
  }
  if (il_kraw < n - 1) {
    set<int> S;
    for (int i = 0; i < n; ++i) S.insert(Find(i));
    if (S.size() >= 3) {
      for (int i = 0; i < q; ++i) cout << "-1" << endl;
    } else {
      for (int i = 0; i < q; ++i) {
        if (Find(a[i]) != Find(b[i]))
          cout << mst << endl;
        else
          cout << "-1" << endl;
      }
    }
  } else {
    vector<int> oj(n), wlk(n), nr(n), odl(n);
    odl[0] = 0;
    dfs(0, -1, G, oj, wlk, nr, odl);
    vector<vector<int> > P(17, vector<int>(n));
    P[0][0] = 0;
    for (int i = 1; i < n; ++i) P[0][i] = oj[i];
    for (int i = 1; i < 17; ++i)
      for (int j = 0; j < n; ++j) P[i][j] = P[i - 1][P[i - 1][j]];
    vector<vector<int> > maxy(17, vector<int>(n));
    maxy[0][0] = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < G[i].size(); ++j)
        if (oj[G[i][j].a] == i) maxy[0][G[i][j].a] = G[i][j].c;
    for (int i = 1; i < 17; ++i)
      for (int j = 0; j < n; ++j)
        maxy[i][j] = max(maxy[i - 1][j], maxy[i - 1][P[i - 1][j]]);
    for (int i = 0; i < q; ++i) {
      int lca = LCA(P, a[i], b[i], nr, wlk);
      cout << mst - max(Daj(a[i], odl[a[i]] - odl[lca], maxy, P),
                        Daj(b[i], odl[b[i]] - odl[lca], maxy, P))
           << endl;
    }
  }
  return 0;
}