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 fastIO {
  inline fastIO operator>>(int& num) {
    num = 0;
    char c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    bool foo = 0;
    if (c == '-') {
      foo = 1;
      c = getchar();
    }
    while (c >= '0' && c <= '9') {
      num = (num << 3) + (num << 1) + c - '0';
      c = getchar();
    }
    if (foo) num = -num;
    return *this;
  }
  inline fastIO operator>>(long long& num) {
    num = 0;
    char c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    bool foo = 0;
    if (c == '-') {
      foo = 1;
      c = getchar();
    }
    while (c >= '0' && c <= '9') {
      num = (num << 3) + (num << 1) + c - '0';
      c = getchar();
    }
    if (foo) num = -num;
    return *this;
  }
  inline fastIO operator>>(float& num) {
    scanf("%f", &num);
    return *this;
  }
  inline fastIO operator>>(double& num) {
    scanf("%lf", &num);
    return *this;
  }
  inline fastIO operator>>(long double& num) {
    scanf("%Lf", &num);
    return *this;
  }
  inline fastIO operator>>(char& num) {
    num = getchar();
    while (num == ' ' || num == '\n') num = getchar();
    return *this;
  }
  inline fastIO operator>>(char* num) {
    int cnt = 0;
    char c = getchar();
    while (c == ' ' || c == '\n') c = getchar();
    while (c != ' ' && c != '\n') {
      num[cnt++] = c;
      c = getchar();
    }
    num[cnt] = 0;
    return *this;
  }
  inline fastIO operator>>(string& num) {
    cin >> num;
    return *this;
  }
  inline void printInt(const int& num) {
    if (num < 10) {
      putchar(num + '0');
      return;
    }
    printInt(num / 10);
    putchar((num % 10) + '0');
  }
  inline void printINT(const long long& num) {
    if (num < 10) {
      putchar(num + '0');
      return;
    }
    printINT(num / 10);
    putchar((num % 10) + '0');
  }
  inline fastIO operator<<(const int& num) {
    if (num < 0)
      putchar('-'), printInt(-num);
    else
      printInt(num);
    return *this;
  }
  inline fastIO operator<<(const long long& num) {
    if (num < 0)
      putchar('-'), printINT(-num);
    else
      printINT(num);
    return *this;
  }
  inline fastIO operator<<(const float& num) {
    printf("%.10f", num);
    return *this;
  }
  inline fastIO operator<<(const double& num) {
    printf("%.16lf", num);
    return *this;
  }
  inline fastIO operator<<(const long double& num) {
    printf("%.20Lf", num);
    return *this;
  }
  inline fastIO operator<<(const char& num) {
    putchar(num);
    return *this;
  }
  inline fastIO operator<<(const char* num) {
    for (int i = 0; num[i]; i++) putchar(num[i]);
    return *this;
  }
  inline fastIO operator<<(const string& num) {
    cout << num;
    return *this;
  }
} fio;
struct BinCharGay {
  int fa[100007];
  void init() {
    for (int i = 0; i < 100007; i++) {
      fa[i] = i;
    }
  }
  int root(int x) { return fa[x] == x ? x : (fa[x] = root(fa[x])); }
  void conn(int x, int y) { fa[root(x)] = root(y); }
} dsu;
int lgl[100007];
vector<pair<int, int> > nei[100007];
void dfs(int now, int sig) {
  lgl[now] = sig;
  for (pair<int, int> i : nei[now]) {
    if (!lgl[i.first]) {
      dfs(i.first, sig);
    }
  }
}
int n, m;
int k;
pair<int, pair<int, int> > egs[200007];
vector<pair<int, int> > nei2[100007];
long long cnteg = 0;
int fa[25][100007];
int ceng[100007];
int mxval[25][100007];
void dfs2(int now = 1, int lst = 0, int val = 0) {
  fa[0][now] = lst;
  ceng[now] = ceng[lst] + 1;
  mxval[0][now] = val;
  for (pair<int, int> i : nei2[now]) {
    if (i.first != lst) {
      dfs2(i.first, now, i.second);
    }
  }
}
int LCAmax(int a, int b) {
  if (ceng[b] > ceng[a]) {
    swap(a, b);
  }
  int maxv = 0, tomove = ceng[a] - ceng[b];
  for (int i = 0; i <= 20; i++) {
    if ((((tomove) >> (i)) & 1)) {
      maxv = max(maxv, mxval[i][a]);
      a = fa[i][a];
    }
  }
  if (a == b) {
    return maxv;
  }
  for (int i = 20; i >= 0; i--) {
    if (fa[i][a] != fa[i][b]) {
      maxv = max(maxv, mxval[i][a]);
      maxv = max(maxv, mxval[i][b]);
      a = fa[i][a];
      b = fa[i][b];
    }
  }
  maxv = max(maxv, mxval[0][a]);
  maxv = max(maxv, mxval[0][b]);
  return maxv;
}
int main() {
  fio >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    fio >> a >> b >> c;
    nei[a].push_back(make_pair(b, c));
    nei[b].push_back(make_pair(a, c));
    egs[i] = make_pair(c, make_pair(a, b));
  }
  sort(egs, egs + m);
  int CntLianTongKuai = 0;
  for (int i = 1; i <= n; i++) {
    if (!lgl[i]) {
      dfs(i, ++CntLianTongKuai);
    }
  }
  if (CntLianTongKuai > 2) {
    fio >> k;
    while (k--) {
      int junk, rubbish;
      fio >> junk >> rubbish;
      fio << "-1\n";
    }
    return 0;
  }
  dsu.init();
  for (int i = 0; i < m; i++) {
    if (dsu.root(egs[i].second.first) != dsu.root(egs[i].second.second)) {
      nei2[egs[i].second.first].push_back(
          make_pair(egs[i].second.second, egs[i].first));
      nei2[egs[i].second.second].push_back(
          make_pair(egs[i].second.first, egs[i].first));
      dsu.conn(egs[i].second.first, egs[i].second.second);
      cnteg += egs[i].first;
    }
  }
  if (CntLianTongKuai == 2) {
    fio >> k;
    while (k--) {
      int a, b;
      fio >> a >> b;
      if (lgl[a] == lgl[b]) {
        fio << "-1\n";
      } else {
        fio << cnteg << '\n';
      }
    }
    return 0;
  } else {
    fio >> k;
    dfs2();
    for (int i = 1; i <= 20; i++) {
      for (int j = 1; j <= n; j++) {
        fa[i][j] = fa[i - 1][fa[i - 1][j]];
        mxval[i][j] = max(mxval[i - 1][j], mxval[i - 1][fa[i - 1][j]]);
      }
    }
    while (k--) {
      int a, b;
      fio >> a >> b;
      fio << cnteg - LCAmax(a, b) << '\n';
    }
  }
  return 0;
}