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 base = 1000000007;
const int MAXN = 100100;
long long sumsq[MAXN], sum2[MAXN];
long long dist1[MAXN];
long long sumsqrest[MAXN], sum2rest[MAXN];
int ac[MAXN][20];
long long sz[MAXN];
vector<pair<int, int> > v[MAXN];
int n;
int tim, tin[MAXN], tout[MAXN];
void dfs(int x, int pr) {
  tin[x] = tim;
  tim++;
  ac[x][0] = pr;
  for (int i = 1; i < 20; i++) ac[x][i] = ac[ac[x][i - 1]][i - 1];
  sz[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int to = v[x][i].first;
    int add = v[x][i].second;
    if (to == pr) continue;
    dist1[to] = dist1[x] + add;
    dist1[to] %= base;
    dfs(to, x);
    sz[x] += sz[to];
    sum2[x] += (sum2[to] + 2 * add * sz[to]);
    sum2[x] %= base;
    sumsq[x] += sumsq[to];
    sumsq[x] %= base;
    sumsq[x] += (sum2[to] * add);
    sumsq[x] %= base;
    sumsq[x] += sz[to] * add % base * add % base;
    sumsq[x] %= base;
  }
  tout[x] = tim;
  tim++;
}
void dfs2(int x, int pr) {
  for (int i = 0; i < v[x].size(); i++) {
    int to = v[x][i].first;
    int add = v[x][i].second;
    if (to == pr) continue;
    long long szh = n - sz[to];
    long long sumsqh = sumsqrest[x] - (sum2[to] * add) - sumsq[to];
    sumsqh += base * base;
    sumsqh %= base;
    sumsqh -= sz[to] * add % base * add % base;
    sumsqh %= base;
    long long sum2h = sum2rest[x] - 2 * sz[to] * add % base - sum2[to];
    sum2h += base * base;
    sum2h %= base;
    sumsqrest[to] = sumsq[to];
    sum2rest[to] = sum2[to];
    sum2rest[to] += (sum2h + 2 * add * szh);
    sum2rest[to] %= base;
    sumsqrest[to] += sumsqh;
    sumsqrest[to] %= base;
    sumsqrest[to] += (sum2h * add);
    sumsqrest[to] %= base;
    sumsqrest[to] += szh * add % base * add % base;
    sumsqrest[to] %= base;
    dfs2(to, x);
  }
}
bool is_ac(int a, int b) { return (tin[a] <= tin[b] && tout[b] <= tout[a]); }
int lca(int a, int b) {
  if (is_ac(a, b)) return a;
  if (is_ac(b, a)) return b;
  for (int i = 19; i >= 0; i--) {
    if (!is_ac(ac[b][i], a)) b = ac[b][i];
  }
  return ac[b][0];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int aa, bb, cc;
    scanf("%d%d%d", &aa, &bb, &cc);
    v[aa].push_back(make_pair(bb, cc));
    v[bb].push_back(make_pair(aa, cc));
  }
  tin[0] = -1;
  tout[0] = (1 << 20);
  dfs(1, 0);
  sumsqrest[1] = sumsq[1];
  sum2rest[1] = sum2[1];
  dfs2(1, 0);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int aa, bb;
    scanf("%d%d", &aa, &bb);
    int o = lca(aa, bb);
    long long dist = dist1[aa] + dist1[bb] - 2 * dist1[o];
    long long F, S;
    if (!is_ac(bb, aa)) {
      F = sumsq[bb] + dist * sum2[bb] + sz[bb] * dist % base * dist % base;
      F %= base;
      S = sumsqrest[aa] - F;
      S += base * base;
      S %= base;
    } else {
      long long szr = n - sz[bb];
      F = sumsqrest[aa] -
          (sumsqrest[bb] - sumsq[bb] + szr * dist % base * dist % base +
           (sum2rest[bb] - sum2[bb] + base) * dist % base);
      F += base * base;
      F %= base;
      S = sumsqrest[aa] - F;
      S += base * base;
      S %= base;
    }
    long long ans = F - S;
    ans += base * base;
    ans %= base;
    cout << ans << "\n";
  }
  return 0;
}
