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 int MAXN = 1e5 + 6.66;
const int LOGMAXN = 20;
const long long mod = 1e9 + 7;
vector<pair<int, long long>> tree[MAXN];
int par[MAXN];
long long upedge[MAXN];
int sz[MAXN];
int h[MAXN];
int lca[LOGMAXN][MAXN];
long long sum[LOGMAXN][MAXN];
long long down[MAXN];
long long down2[MAXN];
long long up[MAXN];
long long up2[MAXN];
long long tot[MAXN];
void lca_init_dfs(int v = 1, int p = 0, int hei = 0, int wei = 0) {
  par[v] = p;
  h[v] = hei;
  upedge[v] = wei;
  for (auto x : tree[v])
    if (x.first != p) lca_init_dfs(x.first, v, hei + 1, x.second);
}
void init_lca(int n) {
  lca_init_dfs();
  for (int i = 1; i <= n; i++) lca[0][i] = par[i], sum[0][i] = upedge[i];
  for (int i = 1; i < LOGMAXN; i++)
    for (int j = 1; j <= n; j++)
      lca[i][j] = lca[i - 1][lca[i - 1][j]],
      sum[i][j] = sum[i - 1][j] + sum[i - 1][lca[i - 1][j]];
}
int get_par(int v, int x) {
  for (; x; x ^= x & -x) v = lca[__builtin_ctz(x)][v];
  return v;
}
bool is_anc(int v, int u) {
  if (h[v] > h[u]) return false;
  return get_par(u, h[u] - h[v]) == v;
}
int get_lca(int v, int u) {
  if (h[v] > h[u]) swap(u, v);
  u = get_par(u, h[u] - h[v]);
  if (u == v) return v;
  for (int i = LOGMAXN - 1; i > -1; i--)
    if ((1 << i) <= h[v] && lca[i][v] != lca[i][u])
      u = lca[i][u], v = lca[i][v];
  return lca[0][u];
}
long long get_path_par(int v, int p) {
  long long ans = 0;
  for (int i = LOGMAXN - 1; i > -1; i--)
    if (h[v] - (1 << i) >= h[p]) (ans += sum[i][v]) %= mod, v = lca[i][v];
  return ans;
}
long long get_path(int v, int u) {
  int lc = get_lca(u, v);
  return (get_path_par(u, lc) + get_path_par(v, lc)) % mod;
}
long long pow2_sum(long long sw2, long long sw, long long x, long long s) {
  sw2 %= mod, sw %= mod, x %= mod, s %= mod;
  if (sw2 < 0) sw2 += mod;
  if (sw < 0) sw += mod;
  if (x < 0) x += mod;
  return (sw2 + 2LL * x * sw % mod + 1LL * x * x % mod * s % mod) % mod;
}
void dfs_up(int v = 1, int p = 0) {
  sz[v] = 1;
  for (auto x : tree[v])
    if (x.first != p) {
      dfs_up(x.first, v);
      sz[v] += sz[x.first];
      (down[v] += down[x.first] + x.second * sz[x.first]) %= mod;
      (down2[v] +=
       pow2_sum(down2[x.first], down[x.first], x.second, sz[x.first])) %= mod;
    }
}
void dfs_down(int v = 1, int p = 0, long long upp = 0, long long upp2 = 0) {
  upp %= mod, upp2 %= mod;
  up[v] = upp;
  up2[v] = upp2;
  tot[v] = (up2[v] + down2[v]) % mod;
  for (auto x : tree[v])
    if (x.first != p) {
      long long ss = upp + down[v] - down[x.first] + 2LL * mod +
                     1LL * (sz[1] - 2 * sz[x.first]) * x.second % mod;
      ss %= mod;
      long long ss2 = pow2_sum(
          upp2 + down2[v] + mod -
              pow2_sum(down2[x.first], down[x.first], x.second, sz[x.first]),
          upp + down[v] - down[x.first] - sz[x.first] * x.second % mod +
              2LL * mod,
          x.second, (sz[1] - sz[x.first]));
      dfs_down(x.first, v, ss, ss2);
    }
}
void initiate(int& n) {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    long long z;
    scanf("%d %d %lld", &x, &y, &z);
    tree[x].push_back({y, z});
    tree[y].push_back({x, z});
  }
  init_lca(n);
  dfs_up();
  dfs_down();
}
int main() {
  int n;
  initiate(n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d %d", &u, &v);
    long long ans = 0;
    if (u == v)
      ans = (down2[v] - up2[v] + mod) % mod;
    else if (is_anc(v, u)) {
      long long xx = pow2_sum(up2[v], up[v], get_path_par(u, v), sz[1] - sz[v]);
      (ans = tot[u] - 2LL * xx + 2LL * mod) %= mod;
    } else {
      long long x1 = pow2_sum(down2[v], down[v], get_path(u, v), sz[v]);
      (ans = 2LL * x1 - tot[u] + 2LL * mod) %= mod;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
