Ali is Hamed's little brother and tomorrow is his birthday. Hamed wants his brother to earn his gift so he gave him a hard programming problem and told him if he can successfully solve it, he'll get him a brand new laptop. Ali is not yet a very talented programmer like Hamed and although he usually doesn't cheat but this time is an exception. It's about a brand new laptop. So he decided to secretly seek help from you. Please solve this problem for Ali. 

An n-vertex weighted rooted tree is given. Vertex number 1 is a root of the tree. We define d(u, v) as the sum of edges weights on the shortest path between vertices u and v. Specifically we define d(u, u) = 0. Also let's define S(v) for each vertex v as a set containing all vertices u such that d(1, u) = d(1, v) + d(v, u). Function f(u, v) is then defined using the following formula:

<image>

The goal is to calculate f(u, v) for each of the q given pair of vertices. As the answer can be rather large it's enough to print it modulo 109 + 7.

Input

In the first line of input an integer n (1 ≤ n ≤ 105), number of vertices of the tree is given.

In each of the next n - 1 lines three space-separated integers ai, bi, ci (1 ≤ ai, bi ≤ n, 1 ≤ ci ≤ 109) are given indicating an edge between ai and bi with weight equal to ci.

In the next line an integer q (1 ≤ q ≤ 105), number of vertex pairs, is given.

In each of the next q lines two space-separated integers ui, vi (1 ≤ ui, vi ≤ n) are given meaning that you must calculate f(ui, vi).

It is guaranteed that the given edges form a tree.

Output

Output q lines. In the i-th line print the value of f(ui, vi) modulo 109 + 7.

Examples

Input

5
1 2 1
4 3 1
3 5 1
1 3 1
5
1 1
1 5
2 4
2 1
3 5


Output

10
1000000005
1000000002
23
1000000002


Input

8
1 2 100
1 3 20
2 4 2
2 5 1
3 6 1
3 7 2
6 8 5
6
1 8
2 3
5 8
2 6
4 7
6 1


Output

999968753
49796
999961271
999991235
999958569
45130
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, MOD = 1e9 + 7, lg = 19;
int n, h[MAXN], LCA[MAXN][lg], q;
long long cntd[MAXN], cntu[MAXN], dsr[MAXN], zdt2[MAXN], zdt1[MAXN],
    zdtu1[MAXN], zdtu2[MAXN];
vector<pair<int, long long> > Mat[MAXN];
void topar(int v, int hi, long long val, int p) {
  LCA[v][0] = p;
  h[v] = hi;
  dsr[v] += val;
  dsr[v] %= MOD;
  cntd[v] = 1;
  for (int i = 0; i < Mat[v].size(); i++)
    if (Mat[v][i].first != p) {
      topar(Mat[v][i].first, hi + 1, val + Mat[v][i].second, v);
      cntd[v] += cntd[Mat[v][i].first];
      zdt1[v] += zdt1[Mat[v][i].first] +
                 (cntd[Mat[v][i].first] * Mat[v][i].second) % MOD;
      zdt1[v] %= MOD;
      zdt2[v] += zdt2[Mat[v][i].first] +
                 (cntd[Mat[v][i].first] *
                  ((Mat[v][i].second * Mat[v][i].second) % MOD)) %
                     MOD;
      zdt2[v] += 2 * (zdt1[Mat[v][i].first] * Mat[v][i].second) % MOD;
      zdt2[v] %= MOD;
    }
}
void updup(int v, int p, long long val) {
  if (v != 1) {
    cntu[v] = cntu[p] + cntd[p] - cntd[v];
    zdtu1[v] += zdtu1[p] + zdt1[p] - zdt1[v] - (val * cntd[v]) % MOD +
                (cntu[v] * val) % MOD;
    zdtu1[v] %= MOD;
    zdtu2[v] = zdtu2[p];
    zdtu2[v] += (cntu[v] * ((val * val) % MOD)) % MOD;
    zdtu2[v] += (val * (zdtu1[p] + zdt1[p] - zdt1[v] - (val * cntd[v]) % MOD) %
                 MOD * 2) %
                MOD;
    zdtu2[v] += zdt2[p] - zdt2[v] - (cntd[v] * ((val * val) % MOD)) % MOD -
                2 * (zdt1[v] * val) % MOD;
    zdtu2[v] %= MOD;
  }
  for (int i = 0; i < Mat[v].size(); i++)
    if (Mat[v][i].first != p) updup(Mat[v][i].first, v, Mat[v][i].second);
}
int goup(int v, int dis) {
  int k = 0;
  while (dis) {
    if (dis % 2) v = LCA[v][k];
    k++;
    dis /= 2;
  }
  return v;
}
int getLCA(int v, int u) {
  if (h[v] < h[u]) swap(u, v);
  int dis = h[v] - h[u];
  v = goup(v, dis);
  if (v == u) return v;
  for (int i = lg - 1; i >= 0; i--)
    if (LCA[v][i] != LCA[u][i]) v = LCA[v][i], u = LCA[u][i];
  return LCA[u][0];
}
long long getdis(int v, int u) {
  return (dsr[v] + dsr[u] - 2 * dsr[getLCA(v, u)]) % MOD;
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    Mat[a].push_back({b, c});
    Mat[b].push_back({a, c});
  }
  topar(1, 0, 0, 1);
  updup(1, 1, 0);
  for (int i = 1; i < lg; i++)
    for (int j = 1; j <= n; j++) LCA[j][i] = LCA[LCA[j][i - 1]][i - 1];
  cin >> q;
  while (q--) {
    int v, u;
    cin >> u >> v;
    if (u == 10) u = 10;
    long long d = getdis(v, u);
    long long S = zdt2[u] + zdtu2[u];
    if (getLCA(v, u) == v) {
      S -= 2 * (zdtu2[v] + (cntu[v] * ((d * d) % MOD)) % MOD +
                (((d * zdtu1[v]) % MOD) * 2) % MOD);
      S %= MOD, S += MOD, S %= MOD;
      cout << S << endl;
    } else {
      long long res = 2 * (zdt2[v] + (cntd[v] * ((d * d) % MOD)) % MOD +
                           (((d * zdt1[v]) % MOD) * 2) % MOD);
      res -= S;
      res %= MOD, res += MOD, res %= MOD;
      cout << res << endl;
    }
  }
}
