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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 1e5 + 100;
const long long LOG = 19;
const long long MOD = 1e9 + 7;
vector<pair<long long, long long>> g[N];
long long up[N][LOG], tin[N], tout[N], d0[N], d1[N], d2[N], sizes[N], ans[N],
    ans1[N], ans2[N];
long long timer = 0;
long long n;
long long add(long long a, long long b) {
  a += b;
  a %= MOD;
  if (a < 0) {
    a += MOD;
  }
  return a;
}
long long mul(long long a, long long b) { return 1ll * a * b % MOD; }
void dfs0(long long v, long long p) {
  tin[v] = timer++;
  sizes[v] = 1;
  for (long long i = 1; i < LOG; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  for (long long i = 0; i < (long long)g[v].size(); i++) {
    if (g[v][i].first == p) {
      g[v].erase(g[v].begin() + i);
      break;
    }
  }
  for (auto i : g[v]) {
    assert(i.first != p);
    up[i.first][0] = v;
    d0[i.first] = add(d0[v], i.second);
    dfs0(i.first, v);
    sizes[v] += sizes[i.first];
  }
  tout[v] = timer;
}
long long anc(long long a, long long b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
long long lca(long long v, long long u) {
  if (anc(v, u)) {
    return v;
  }
  if (anc(u, v)) {
    return u;
  }
  for (long long i = LOG - 1; i >= 0; i--) {
    if (!anc(up[v][i], u)) {
      v = up[v][i];
    }
  }
  return up[v][0];
}
long long getDist(long long v, long long u) {
  long long w = lca(v, u);
  long long ret = add(d0[v], d0[u]);
  ret = add(ret, mul(-2, d0[w]));
  return ret;
}
long long get_cost(long long d, long long d1, long long d2, long long n) {
  long long ret = mul(mul(d, d), n);
  ret = add(ret, mul(2 * d, d1));
  ret = add(ret, d2);
  return ret;
}
void dfs1(long long v) {
  for (auto i : g[v]) {
    long long u = i.first, c = i.second;
    dfs1(u);
    d2[v] = add(d2[v], get_cost(c, d1[u], d2[u], sizes[u]));
    d1[v] = add(d1[v], mul(c, sizes[u]));
    d1[v] = add(d1[v], d1[u]);
  }
}
void dfs2(long long v, long long a, long long b) {
  ans[v] = add(ans[v], d2[v]);
  ans[v] = add(ans[v], b);
  ans1[v] = a;
  ans2[v] = b;
  a = add(a, d1[v]);
  b = add(b, d2[v]);
  for (auto i : g[v]) {
    long long u = i.first, c = i.second;
    long long ta = a;
    ta = add(ta, -d1[u]);
    ta = add(ta, -mul(c, sizes[u]));
    long long tb = b;
    tb = add(tb, -get_cost(c, d1[u], d2[u], sizes[u]));
    tb = get_cost(c, ta, tb, n - sizes[u]);
    ta = add(ta, mul(c, n - sizes[u]));
    dfs2(u, ta, tb);
  }
}
long long stupid(long long v) {
  long long ret = 0;
  for (long long i = 0; i < n; i++) {
    long long D = getDist(v, i);
    ret = add(ret, mul(D, D));
  }
  return ret;
}
long long solve(long long v, long long u) {
  swap(v, u);
  long long ret = 0;
  long long D = getDist(v, u);
  if (anc(v, u)) {
    ret = ans[u];
    long long cur = get_cost(D, ans1[v], ans2[v], n - sizes[v]);
    ret = add(ret, -mul(2, cur));
  } else {
    ret = add(0, -ans[u]);
    long long cur = 0;
    cur = get_cost(D, d1[v], d2[v], sizes[v]);
    ret = add(ret, mul(2, cur));
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long v, u, c;
    cin >> v >> u >> c;
    v--;
    u--;
    g[v].emplace_back(u, c);
    g[u].emplace_back(v, c);
  }
  dfs0(0, -1);
  dfs1(0);
  dfs2(0, 0, 0);
  long long q;
  cin >> q;
  while (q--) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    cout << solve(v, u) << '\n';
  }
}
