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 = 100100;
const int LOGMAXN = 18;
const int MOD = 1e+9 + 7;
struct node {
  int xsum, xsqr, xcnt;
  node() : xsum(0), xsqr(0), xcnt(0) {}
};
int N;
vector<pair<int, int> > V[MAXN];
int dad[MAXN][LOGMAXN];
int dep[MAXN];
int sum[MAXN];
node data[MAXN];
node str[MAXN][LOGMAXN];
inline int sqr(int x) { return ((long long)x * x) % MOD; }
inline int add(int a, int b) {
  int ret = a + b;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
inline int sub(int a, int b) {
  int ret = a - b + MOD;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
inline int mul(int a, int b) { return ((long long)a * b) % MOD; }
inline int f(int curr, int k) {
  return add(mul(data[curr].xcnt, sqr(k)),
             add(mul(2, mul(k, data[curr].xsum)), data[curr].xsqr));
}
namespace tr {
int depth = 0;
int curr_sum = 0;
node build(int curr, int prev = 0) {
  dep[curr] = depth;
  sum[curr] = curr_sum;
  dad[curr][0] = prev;
  for (int i = 1; i < LOGMAXN - 1; ++i)
    dad[curr][i] = dad[dad[curr][i - 1]][i - 1];
  node ret;
  ret.xcnt = 1;
  for (pair<int, int> nxt : V[curr]) {
    if (nxt.first == prev) continue;
    depth += 1;
    curr_sum = add(curr_sum, nxt.second);
    node get = build(nxt.first, curr);
    ret.xcnt = add(ret.xcnt, get.xcnt);
    ret.xsum = add(ret.xsum, mul(get.xcnt, nxt.second));
    ret.xsum = add(ret.xsum, get.xsum);
    ret.xsqr = add(ret.xsqr, mul(get.xcnt, sqr(nxt.second)));
    ret.xsqr = add(ret.xsqr, get.xsqr);
    ret.xsqr = add(ret.xsqr, mul(2, mul(nxt.second, get.xsum)));
    curr_sum = sub(curr_sum, nxt.second);
    depth -= 1;
  }
  return data[curr] = ret;
}
void dfs(int curr, int prev = 0) {
  long long tmp = 0;
  str[curr][0].xsum = sub(data[dad[curr][0]].xsum, data[curr].xsum);
  str[curr][0].xsum =
      sub(str[curr][0].xsum,
          mul(data[curr].xcnt, sub(sum[curr], sum[dad[curr][0]])));
  str[curr][0].xcnt = sub(data[dad[curr][0]].xcnt, data[curr].xcnt);
  str[curr][0].xsqr =
      sub(data[dad[curr][0]].xsqr, f(curr, sub(sum[curr], sum[dad[curr][0]])));
  for (int i = 1; i < LOGMAXN - 1; ++i) {
    str[curr][i].xcnt =
        str[curr][i - 1].xcnt + str[dad[curr][i - 1]][i - 1].xcnt;
    int par1 = dad[curr][i - 1];
    int par2 = dad[curr][i];
    int edge_val = sub(sum[dad[curr][0]], sum[dad[par1][0]]);
    tmp = str[curr][i - 1].xsum + (long long)str[par1][i - 1].xsum +
          (long long)edge_val * str[par1][i - 1].xcnt;
    str[curr][i].xsum = (tmp % MOD + MOD) % MOD;
    int dist = sub(sum[dad[curr][0]], sum[dad[par1][0]]);
    str[curr][i].xsqr = add(str[curr][i - 1].xsqr, str[par1][i - 1].xsqr);
    str[curr][i].xsqr =
        add(str[curr][i].xsqr, mul(2, mul(str[par1][i - 1].xsum, dist)));
    str[curr][i].xsqr =
        add(str[curr][i].xsqr, mul(str[par1][i - 1].xcnt, sqr(dist)));
  }
  for (pair<int, int> nxt : V[curr]) {
    if (nxt.first == prev) continue;
    dfs(nxt.first, curr);
  }
}
}  // namespace tr
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 16; i >= 0; --i) {
    if (dep[v] - (1 << i) < dep[u]) continue;
    v = dad[v][i];
  }
  for (int i = 16; i >= 0; --i) {
    int nu = dad[u][i];
    int nv = dad[v][i];
    if (nu == nv) continue;
    u = nu;
    v = nv;
  }
  if (u != v) u = dad[u][0];
  return u;
}
int query(int u, int v) {
  int LCA = lca(u, v);
  int dist = sum[u] + sum[v] - 2 * sum[LCA];
  if (LCA != v || u == v) return f(v, dist);
  int ret = data[u].xsqr;
  int curr = u;
  for (int i = 16; i >= 0; --i) {
    if (dep[curr] - (1 << i) < dep[v]) continue;
    const node get = str[curr][i];
    int dist = sub(sum[u], sum[dad[curr][0]]);
    curr = dad[curr][i];
    int tmp = add(get.xsqr, mul(sqr(dist), get.xcnt));
    tmp = add(tmp, mul(2, mul(get.xsum, dist)));
    ret = add(ret, tmp);
    ret = (ret + MOD) % MOD;
  }
  return (ret % MOD + MOD) % MOD;
}
int main(void) {
  scanf("%d", &N);
  for (int i = 1; i < N; ++i) {
    int u, v, x;
    scanf("%d%d%d", &u, &v, &x);
    V[u].push_back({v, x});
    V[v].push_back({u, x});
  }
  tr::build(1);
  tr::dfs(1);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    int LCA = lca(u, v);
    int dist = sum[u] + sum[v] - 2 * sum[LCA];
    printf("%d\n", (sub(mul(2, query(u, v)), query(u, 1)) % MOD + MOD) % MOD);
  }
  return 0;
}
