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;
vector<int> adj[100005];
vector<long long> vals[100005];
long long sdp[100005], sum[100005], dp[100005], upper[100005], upsum[100005];
long long ssum[100005];
int sz[100005];
long long dist[100005];
int depth[100005];
long long dist_to_p[100005];
int pa[100005][21] = {0};
void dfs(int x, int p) {
  int omar = adj[x].size();
  sz[x] = 1;
  sum[0] = 0;
  sdp[0] = 0;
  for (int i = 0; i < omar; ++i) {
    if (adj[x][i] == p) continue;
    int u = adj[x][i];
    depth[u] = depth[x] + 1;
    pa[u][0] = x;
    dist[u] = dist[x] + vals[x][i];
    dist_to_p[u] = vals[x][i];
    dfs(u, x);
    sum[x] += sz[u] * vals[x][i] + sum[u];
    sum[x] %= 1000000007;
    sz[x] += sz[u];
    sdp[x] += (sz[u] * ((vals[x][i] * vals[x][i]) % 1000000007)) % 1000000007 +
              2 * sum[u] * vals[x][i] % 1000000007 + sdp[u];
    sdp[x] %= 1000000007;
  }
}
void solve(int x, int p) {
  dp[x] = sdp[x];
  ssum[x] = sum[x];
  if (x != 1) {
    int szupper = sz[1] - sz[x];
    dp[x] +=
        (szupper * ((dist_to_p[x] * dist_to_p[x]) % 1000000007)) % 1000000007 +
        2 * upsum[x] * dist_to_p[x] % 1000000007 + upper[x];
    dp[x] %= 1000000007;
    sum[x] += upsum[x] + szupper * dist_to_p[x];
    sum[x] %= 1000000007;
  }
  int omar = adj[x].size();
  for (int i = 0; i < omar; ++i) {
    if (adj[x][i] == p) continue;
    int u = adj[x][i];
    upsum[u] = sum[x] - sz[u] * vals[x][i] - sum[u];
    upsum[u] %= 1000000007;
    if (upsum[u] < 0) upsum[u] += 1000000007;
    upper[u] = dp[x];
    upper[u] -=
        (sz[u] * ((vals[x][i] * vals[x][i]) % 1000000007)) % 1000000007 +
        2 * sum[u] * vals[x][i] % 1000000007 + sdp[u];
    upper[u] %= 1000000007;
    if (upper[u] < 0) upper[u] += 1000000007;
  }
  for (int i = 0; i < omar; ++i) {
    if (adj[x][i] == p) continue;
    int u = adj[x][i];
    solve(u, x);
  }
}
int mxlog = 0;
int n;
void blca() {
  while ((1 << mxlog) <= n) mxlog++;
  for (int j = 1; j < mxlog; ++j)
    for (int i = 1; i <= n; ++i) pa[i][j] = pa[pa[i][j - 1]][j - 1];
}
int lca(int x, int y) {
  if (depth[x] < depth[y]) return lca(y, x);
  int diff = depth[x] - depth[y];
  for (int i = 0; i < mxlog; ++i)
    if ((diff & (1 << i))) x = pa[x][i];
  if (x == y) return x;
  for (int i = mxlog - 1; i >= 0; --i)
    if (pa[x][i] != pa[y][i]) x = pa[x][i], y = pa[y][i];
  return pa[x][0];
}
int go_up(int x, int diff) {
  for (int i = 0; i < mxlog; ++i)
    if ((diff & (1 << i))) x = pa[x][i];
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, val;
    scanf("%d%d%d", &u, &v, &val);
    adj[u].push_back(v);
    adj[v].push_back(u);
    vals[u].push_back(val);
    vals[v].push_back(val);
  }
  dfs(1, -1);
  solve(1, -1);
  blca();
  int q;
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    long long in;
    int lc = lca(u, v);
    long long dis =
        (dist[u] + dist[v]) % 1000000007 - 2 * dist[lc] % 1000000007;
    dis %= 1000000007;
    if (dis < 0) dis += 1000000007;
    long long omar = 0;
    in = (sz[v] * ((dis * dis) % 1000000007)) % 1000000007 +
         2 * ssum[v] * dis % 1000000007 + sdp[v];
    in %= 1000000007;
    if (v != u && lc == v) {
      int c = go_up(u, depth[u] - depth[v] - 1);
      long long dis2 = dist_to_p[c];
      dis += dis2;
      omar = (sz[c] * ((dis * dis) % 1000000007)) % 1000000007 +
             2 * (ssum[c]) * dis % 1000000007 + sdp[c];
      omar %= 1000000007;
      in -= omar;
      if (in < 0) in += 1000000007;
      int szupper = sz[1] - sz[c];
      dis -= dis2;
      in += dp[u];
      in %= 1000000007;
      in -= (((szupper * ((dis * dis) % 1000000007)) % 1000000007 +
              2 * upsum[c] * dis % 1000000007) %
                 1000000007 +
             upper[c]) %
            1000000007;
      in %= 1000000007;
      omar %= 1000000007;
      dis -= dis2;
    }
    if (in < 0) in += 1000000007;
    in %= 1000000007;
    in *= 2;
    in %= 1000000007;
    in -= dp[u];
    if (in < 0) in += 1000000007;
    cout << in << endl;
  }
}
