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;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int N = 100009;
const int logN = 22;
const int sqrN = 450;
const int MOD = 1000000007;
const int INF = 1e9 + 100;
const long long INF64 = 1e14;
const long double PI = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int n, m, q;
vector<pair<int, int> > g[N];
vector<pair<int, pair<int, int> > > edge;
int cntComp;
int col[N], tin[N], tout[N], timer;
int up[N][logN];
int mx[N][logN];
int dsu[N], rnk[N];
long long sumLen;
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
void dfs(int v, int p, int len) {
  col[v] = cntComp;
  tin[v] = ++timer;
  up[v][0] = p;
  mx[v][0] = len;
  for (int i = 1; i < logN; ++i) {
    up[v][i] = up[up[v][i - 1]][i - 1];
    mx[v][i] = max(mx[v][i - 1], mx[up[v][i - 1]][i - 1]);
  }
  for (int i = 0; i < (int)((int)(g[v].size())); ++i) {
    int to = g[v][i].first;
    if (!col[to]) dfs(to, v, g[v][i].second);
  }
  tout[v] = ++timer;
}
int find(int v) { return (dsu[v] == v ? v : dsu[v] = find(dsu[v])); }
void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (rnk[a] < rnk[b]) swap(a, b);
    dsu[b] = a;
    if (rnk[a] == rnk[b]) ++rnk[a];
  }
}
int calc(int u, int v) {
  int res = -INF;
  int u2 = u;
  if (upper(v, u)) {
    for (int i = logN - 1; i >= 0; --i)
      if (!upper(up[u][i], v)) {
        res = max(res, mx[u][i]);
        u = up[u][i];
      }
    res = max(res, mx[u][0]);
    return res;
  }
  if (upper(u, v)) {
    swap(u, v);
    for (int i = logN - 1; i >= 0; --i)
      if (!upper(up[u][i], v)) {
        res = max(res, mx[u][i]);
        u = up[u][i];
      }
    res = max(res, mx[u][0]);
    return res;
  }
  for (int i = logN - 1; i >= 0; --i)
    if (!upper(up[u][i], v)) {
      res = max(res, mx[u][i]);
      u = up[u][i];
    }
  res = max(res, mx[u][0]);
  u = u2;
  swap(u, v);
  for (int i = logN - 1; i >= 0; --i)
    if (!upper(up[u][i], v)) {
      res = max(res, mx[u][i]);
      u = up[u][i];
    }
  res = max(res, mx[u][0]);
  return res;
}
int main() {
  srand(time(NULL));
  cout << setprecision(10) << fixed;
  cerr << setprecision(10) << fixed;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(m); ++i) {
    int u, v, len;
    scanf("%d%d%d", &u, &v, &len);
    --u, --v;
    edge.push_back(make_pair(len, make_pair(u, v)));
  }
  sort(edge.begin(), edge.end());
  for (int i = 0; i < (int)(n); ++i) dsu[i] = i;
  for (int i = 0; i < (int)((int)(edge.size())); ++i) {
    int u = edge[i].second.first, v = edge[i].second.second;
    if (find(u) != find(v)) {
      sumLen += edge[i].first;
      g[u].push_back(make_pair(v, edge[i].first));
      g[v].push_back(make_pair(u, edge[i].first));
      merge(u, v);
    }
  }
  for (int i = 0; i < (int)(n); ++i)
    if (!col[i]) {
      ++cntComp;
      dfs(i, i, -INF);
    }
  scanf("%d", &q);
  for (int _ = 0; _ < (int)(q); ++_) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    if (cntComp >= 3) {
      puts("-1");
    }
    if (cntComp == 2) {
      if (col[u] == col[v])
        puts("-1");
      else
        printf("%I64d\n", sumLen);
    }
    if (cntComp == 1) {
      printf("%I64d\n", sumLen - calc(u, v));
    }
  }
  return 0;
}