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 long long N = 100100, MOD = 1000 * 1000 * 1000 + 7;
long long n, q;
vector<pair<long long, long long> > adl[N];
long long ks[N], ks2[N], as[N], as2[N], ted[N], anc[N][20], len[N], hei[N];
bool chk[N];
void dfs(long long v) {
  chk[v] = 1;
  ted[v] = 1;
  for (long long i = 0, u, w; i < adl[v].size(); ++i) {
    u = adl[v][i].first;
    w = adl[v][i].second;
    if (!chk[u]) {
      dfs(u);
      ted[v] += ted[u];
      ks[v] += ks[u];
      ks[v] %= MOD;
      ks[v] += w * ted[u];
      ks[v] %= MOD;
      long long w2 = w * w;
      w2 %= MOD;
      long long res = (w * ks[u]) % MOD;
      ks2[v] += 2 * res;
      ks2[v] %= MOD;
      ks2[v] += ks2[u] + w2 * ted[u];
      ks2[v] %= MOD;
    }
  }
}
void dfs(long long v, long long dad, long long wei) {
  chk[v] = 1;
  anc[v][0] = dad;
  len[v] = len[dad] + wei;
  len[v] %= MOD;
  hei[v] = hei[dad] + 1;
  if (!dad) {
    as[v] = ks[v];
    as2[v] = ks2[v];
  } else {
    long long other = n - ted[v];
    long long dis = other - ted[v];
    while (dis < 0) dis += MOD;
    as[v] = as[dad] + wei * (dis);
    as[v] %= MOD;
    long long sdis = as[dad] - 2 * ks[v] - ted[v] * wei;
    if (sdis < 0) sdis += wei * MOD;
    while (sdis < 0) sdis += MOD;
    sdis %= MOD;
    long long w2 = wei * wei;
    w2 %= MOD;
    as2[v] = as2[dad] + w2 * dis;
    as2[v] %= MOD;
    long long res = (wei * sdis) % MOD;
    as2[v] += res * 2;
    as2[v] %= MOD;
  }
  for (long long i = 0, u, w; i < adl[v].size(); ++i) {
    u = adl[v][i].first;
    w = adl[v][i].second;
    if (!chk[u]) dfs(u, v, w);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1, x, y, w; i < n; ++i) {
    cin >> x >> y >> w;
    adl[x].push_back(pair<long long, long long>(y, w));
    adl[y].push_back(pair<long long, long long>(x, w));
  }
  dfs(1);
  memset(chk, 0, sizeof chk);
  dfs(1, 0, 0);
  for (long long i = 1; i < 20; ++i)
    for (long long j = 1; j <= n; ++j) anc[j][i] = anc[anc[j][i - 1]][i - 1];
  cin >> q;
  for (long long i = 1, x, y; i <= q; ++i) {
    cin >> x >> y;
    long long lca, ans = 0, cx = x, cy = y;
    if (hei[x] < hei[y]) swap(x, y);
    long long dis = hei[x] - hei[y];
    for (long long j = 19; j >= 0; --j)
      if (dis & (1 << j)) x = anc[x][j];
    if (x == y) {
      lca = x;
      if (hei[cx] >= hei[cy]) {
        long long fas = len[cx] + len[cy] - 2 * len[lca];
        fas %= MOD;
        long long fas2 = fas * fas;
        fas2 %= MOD;
        long long res = ((fas * (as[cy] - ks[cy])) % MOD);
        ans =
            as2[cx] - 2 * (as2[cy] - ks2[cy] + fas2 * (n - ted[cy]) + 2 * res);
        if (ans < 0) ans += N * MOD;
        while (ans < 0) ans += MOD;
        ans %= MOD;
        cout << ans << "\n";
        continue;
      }
    } else {
      for (long long j = 19; j >= 0; --j)
        if (anc[x][j] != anc[y][j]) {
          x = anc[x][j];
          y = anc[y][j];
        }
      lca = anc[x][0];
    }
    long long fas = len[cx] + len[cy] - 2 * len[lca];
    fas %= MOD;
    long long fas2 = fas * fas;
    fas2 %= MOD;
    ans = ks2[cy] + fas2 * ted[cy];
    ans %= MOD;
    long long res = (fas * ks[cy]) % MOD;
    ans += res * 2;
    ans %= MOD;
    ans = ans - (as2[cx] - ans);
    if (ans < 0) ans += N * MOD;
    while (ans < 0) ans += MOD;
    ans %= MOD;
    cout << ans << "\n";
  }
  return 0;
}
