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 M = (int)1e9 + 7;
const int N = (int)1e5 + 10;
const int L = 17;
int sum0[N], sum1[N], sum2[N], psum0[N], psum1[N], psum2[N], par[L][N], in[N],
    out[N], curt, u, v, w, h[N], delta0[N], delta1[N], delta2[N], n, q;
vector<pair<int, int> > adj[N];
int add(int a, int b) { return (a + b) % M; }
int mult(int a, int b) { return (a * (long long)b) % M; }
bool is_parent(int u, int v) { return (in[u] <= in[v]) && (out[v] <= out[u]); }
int sq_sum(int sum0, int sum1, int sum2, int w) {
  return add(add(sum2, mult(sum1, mult(2, w))), mult(sum0, mult(w, w)));
}
void dfs(int v, int p = -1) {
  in[v] = curt++, par[0][v] = ((p == -1) ? v : p), sum0[v] = 1, sum1[v] = 0,
  sum2[v] = 0;
  for (int i = 0; i < ((int)(adj[v]).size()); ++i) {
    int u = adj[v][i].first, w = adj[v][i].second;
    if (u == p) continue;
    h[u] = add(h[v], w);
    dfs(u, v);
    sum0[v] = add(sum0[v], delta0[u] = sum0[u]);
    sum1[v] = add(sum1[v], delta1[u] = add(sum1[u], mult(sum0[u], w)));
    sum2[v] = add(sum2[v], delta2[u] = sq_sum(sum0[u], sum1[u], sum2[u], w));
  }
  out[v] = curt++;
}
void ndfs(int v, int p = -1) {
  for (int i = 0; i < ((int)(adj[v]).size()); ++i) {
    int u = adj[v][i].first, w = adj[v][i].second;
    if (u == p) continue;
    psum0[u] = add(psum0[v], add(sum0[v], M - delta0[u]));
    psum1[u] = add(psum1[v], add(sum1[v], M - delta1[u]));
    psum2[u] = add(psum2[v], add(sum2[v], M - delta2[u]));
    psum2[u] = sq_sum(psum0[u], psum1[u], psum2[u], w);
    psum1[u] = add(psum1[u], mult(psum0[u], w));
    ndfs(u, v);
  }
}
int lca(int u, int v) {
  if (is_parent(u, v)) return u;
  for (int j = L - 1; j >= 0; --j)
    if (!is_parent(par[j][u], v)) u = par[j][u];
  return par[0][u];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i + 1 < n; ++i) {
    scanf("%d%d%d", &u, &v, &w), --u, --v;
    adj[u].push_back(make_pair(v, w)), adj[v].push_back(make_pair(u, w));
  }
  dfs(0);
  for (int j = 1; j < L; ++j)
    for (int i = 0; i < n; ++i) par[j][i] = par[j - 1][par[j - 1][i]];
  ndfs(0);
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &u, &v), --u, --v;
    w = add(add(h[u], h[v]), M - mult(2, h[lca(u, v)]));
    if (!is_parent(v, u))
      printf("%d\n", add(mult(2, sq_sum(sum0[v], sum1[v], sum2[v], w)),
                         M - add(psum2[u], sum2[u])));
    else
      printf("%d\n", add(M - mult(2, sq_sum(psum0[v], psum1[v], psum2[v], w)),
                         add(psum2[u], sum2[u])));
  }
  return 0;
}
