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;
class sparse_table {
 private:
  int ancestor[100010][20 + 10];
  int N;

 public:
  void init(int n, int *par) {
    int i, j;
    N = n;
    memset(ancestor, -1, sizeof(int) * 100010 * (20 + 10));
    for (i = 0; i < N; ++i) ancestor[i][0] = par[i];
    for (j = 1; (1 << j) < N; ++j) {
      for (i = 0; i < N; ++i) {
        if (ancestor[i][j - 1] < 0) continue;
        ancestor[i][j] = ancestor[ancestor[i][j - 1]][j - 1];
      }
    }
  }
  int query(int u, int v, int *lev) {
    int i;
    if (lev[u] < lev[v]) swap(u, v);
    for (i = 20 - 1; i >= 0; --i) {
      if (lev[u] - (1 << i) < lev[v]) continue;
      u = ancestor[u][i];
    }
    if (u == v) return u;
    for (i = 20 - 1; i >= 0; --i) {
      if (ancestor[u][i] == ancestor[v][i]) continue;
      u = ancestor[u][i];
      v = ancestor[v][i];
    }
    return ancestor[u][0];
  }
};
int ssize[100010];
int outsz[100010];
int rdist[100010];
int indist[100010];
int indist2[100010];
int outdist[100010];
int outdist2[100010];
int par[100010];
int lev[100010];
vector<pair<int, int> > adj[100010];
int N;
inline int mul(int a, int b) { return (1LL * a * b) % (int)((1e9) + 7); }
inline int add(int a, int b) {
  int c = (a + b);
  return c >= (int)((1e9) + 7) ? c - (int)((1e9) + 7) : c;
}
void dfs1(int v, int p, int dpar) {
  rdist[v] = p >= 0 ? add(rdist[p], dpar) : 0;
  par[v] = p;
  lev[v] = p >= 0 ? lev[p] + 1 : 0;
  int i, u, du;
  ssize[v] = 1;
  for (i = 0; i < adj[v].size(); ++i) {
    u = adj[v][i].first;
    if (u == p) continue;
    du = adj[v][i].second;
    dfs1(u, v, du);
    ssize[v] += ssize[u];
    indist[v] = add(indist[v], indist[u]);
    indist[v] = add(indist[v], mul(du, ssize[u]));
    indist2[v] = add(indist2[v], mul(mul(du, du), ssize[u]));
    indist2[v] = add(indist2[v], indist2[u]);
    indist2[v] = add(indist2[v], mul(2, mul(du, indist[u])));
  }
  outsz[v] = N - ssize[v];
}
inline int sub(int a, int b) {
  int c = a - b;
  if (c >= (int)((1e9) + 7)) c -= (int)((1e9) + 7);
  return c < 0 ? c + (int)((1e9) + 7) : c;
}
void dfs2(int v, int p, int dpar) {
  int i;
  if (p < 0) {
    for (i = 0; i < adj[v].size(); ++i)
      dfs2(adj[v][i].first, v, adj[v][i].second);
    return;
  }
  outdist[v] = add(add(outdist[p], indist[p]), mul(dpar, N));
  outdist[v] = sub(outdist[v], add(indist[v], mul(dpar, 2 * ssize[v])));
  int all, all2;
  all = add(outdist[p], indist[p]);
  all2 = add(outdist2[p], indist2[p]);
  outdist2[v] = add(all2, add(mul(dpar, mul(dpar, N)), mul(all, mul(dpar, 2))));
  outdist2[v] = sub(outdist2[v],
                    add(indist2[v], add(mul(dpar, mul(4, indist[v])),
                                        mul(dpar, mul(dpar, 4 * ssize[v])))));
  for (i = 0; i < adj[v].size(); ++i) {
    if (adj[v][i].first == p) continue;
    dfs2(adj[v][i].first, v, adj[v][i].second);
  }
}
sparse_table T;
int get_sum(int u, int v) {
  int all2;
  int q1, q2;
  all2 = add(outdist2[u], indist2[u]);
  int l = T.query(u, v, lev);
  int duv;
  duv = sub(add(rdist[u], rdist[v]), mul(2, rdist[l]));
  if (l == v) {
    q2 = add(outdist2[v],
             add(mul(duv, mul(duv, outsz[v])), mul(mul(2, duv), outdist[v])));
    q1 = sub(all2, q2);
  } else {
    q1 = add(indist2[v],
             add(mul(duv, mul(duv, ssize[v])), mul(mul(2, duv), indist[v])));
    q2 = sub(all2, q1);
  }
  return sub(q1, q2);
}
int main() {
  int i, u, v, q;
  ios_base::sync_with_stdio(0);
  cin >> N;
  for (i = 0; i < N - 1; ++i) {
    cin >> v >> u >> q;
    --u, --v;
    adj[u].push_back(make_pair(v, q));
    adj[v].push_back(make_pair(u, q));
  }
  dfs1(0, -1, 0);
  dfs2(0, -1, 0);
  T.init(N, par);
  cin >> q;
  while (q--) {
    cin >> u >> v;
    --u, --v;
    cout << get_sum(u, v) << '\n';
  }
  return 0;
}
