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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
long long tot[100010];
int sz[100010], p[100010][20], d[100010], a[100010], b[100010], f[100010],
    h[100010], l[100010], aa[100010], bb[100010];
vector<pair<int, int> > g[100010];
void dfs(int u, int fa, int w = 0) {
  sz[u] = 1;
  p[u][0] = fa;
  d[u] = (d[fa] + w) % 1000000007;
  l[u] = l[fa] + 1;
  for (int i = 0; i < g[u].size(); i++) {
    int j = g[u][i].first, w = g[u][i].second;
    if (j == fa) continue;
    dfs(j, u, w);
    sz[u] += sz[j];
    long long v = (a[j] + 1LL * sz[j] * w % 1000000007 * w % 1000000007 +
                   1LL * w * b[j] % 1000000007 * 2) %
                  1000000007;
    a[u] = (a[u] + v) % 1000000007;
    f[j] = v;
    v = b[j] + 1LL * sz[j] * w % 1000000007;
    v %= 1000000007;
    b[u] = (b[u] + v) % 1000000007;
    h[j] = v;
  }
}
void go(int u, int fa, int w = 0, int first = 0, int second = 0) {
  if (u > 1) {
    first = (a[fa] - f[u] + first) % 1000000007;
    if (first < 0) first += 1000000007;
    second = (b[fa] - h[u] + second) % 1000000007;
    if (second < 0) second += 1000000007;
    tot[u] = (first + 1LL * (sz[1] - sz[u]) * w % 1000000007 * w % 1000000007 +
              1LL * w * second % 1000000007 * 2) %
             1000000007;
    first = tot[u];
    second = (second + 1LL * (sz[1] - sz[u]) * w % 1000000007) % 1000000007;
    tot[u] = (tot[u] + a[u]) % 1000000007;
    aa[u] = first, bb[u] = second;
  } else
    tot[1] = a[1];
  for (int i = 0; i < g[u].size(); i++) {
    int j = g[u][i].first, w = g[u][i].second;
    if (j == fa) continue;
    go(j, u, w, first, second);
  }
}
int lca(int a, int b) {
  if (l[a] < l[b]) swap(a, b);
  int h = l[a] - l[b];
  for (int i = 0; i < 18; i++)
    if (h >> i & 1) a = p[a][i];
  if (a == b) return a;
  for (int i = 17; i >= 0; i--)
    if (p[a][i] != p[b][i]) a = p[a][i], b = p[b][i];
  return p[a][0];
}
int main() {
  int T, i, j, m, n, ca = 0, k, now = 0;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    int w;
    scanf("%d%d%d", &j, &k, &w);
    g[j].push_back(make_pair(k, w));
    g[k].push_back(make_pair(j, w));
  }
  dfs(1, 0);
  go(1, 0);
  for (i = 1; i < 19; i++)
    for (j = 1; j <= n; j++) p[j][i] = p[p[j][i - 1]][i - 1];
  scanf("%d", &m);
  while (m--) {
    int u, v, t = 1;
    scanf("%d%d", &u, &v);
    int fa = lca(u, v);
    long long ans = 0;
    if (v == fa) {
      long long w = d[u] - d[v], first = aa[v], second = bb[v],
                z = sz[1] - sz[v];
      if (w < 0) w += 1000000007;
      ans = first + z * w % 1000000007 * w % 1000000007 +
            w * second % 1000000007 * 2;
      ans %= 1000000007;
      t = -1;
    } else {
      long long w = d[u] - d[fa] + d[v] - d[fa], first = a[v], second = b[v],
                z = sz[v];
      w %= 1000000007;
      if (w < 0) w += 1000000007;
      ans = first + z * w % 1000000007 * w % 1000000007 +
            w * second % 1000000007 * 2;
      ans %= 1000000007;
    }
    if (ans < 0) ans += 1000000007;
    ans = 2LL * ans - tot[u];
    ans *= t;
    ans %= 1000000007;
    if (ans < 0) ans += 1000000007;
    printf("%d\n", ans);
  }
}
