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;
template <typename T>
void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chkmin(T &x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  while (c < 48) f |= c == '-', c = getchar();
  while (c > 47) x = x * 10 + (c ^ 48), c = getchar();
  return f ? -x : x;
}
const int maxn = 1e5 + 10, P = 1e9 + 7;
int Inc(int x, int y) { return x + y < P ? x + y : x + y - P; }
int Dec(int x, int y) { return x < y ? x - y + P : x - y; }
void Add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
void Sub(int &x, int y) {
  x -= y;
  if (x < 0) x += P;
}
int qp(int a, int k) {
  int res = 1;
  for (; k; k >>= 1, a = 1ll * a * a % P)
    if (k & 1) res = 1ll * res * a % P;
  return res;
}
int n, q;
int ecnt = 1, h[maxn];
struct edges {
  int nxt, to, w;
} E[maxn << 1];
void addline(int u, int v, int w) { E[++ecnt] = {h[u], v, w}, h[u] = ecnt; }
int sum1[maxn], sum2[maxn];
int fa[maxn], sz[maxn], dep[maxn], son[maxn], top[maxn], dis[maxn], dfn[maxn];
void dfs1(int u, int f) {
  fa[u] = f, sz[u] = 1, dep[u] = dep[f] + 1;
  for (int i = h[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if (v != f) {
      dis[v] = Inc(dis[u], E[i].w), dfs1(v, u);
      if (sz[son[u]] < sz[v]) son[u] = v;
      sz[u] += sz[v], Add(sum1[u], (sum1[v] + 1ll * sz[v] * E[i].w) % P),
          Add(sum2[u], (sum2[v] + 2ll * sum1[v] * E[i].w % P +
                        1ll * E[i].w * E[i].w % P * sz[v] % P) %
                           P);
    }
  }
}
int dp1[maxn], dp2[maxn];
void dfs2(int u, int tp) {
  for (int i = h[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if (v != fa[u]) {
      dp1[v] = (dp1[u] + 1ll * E[i].w * (n - sz[v] * 2 + P) % P) % P;
      dp2[v] = (dp2[u] -
                (1ll * E[i].w * E[i].w % P * sz[v] % P +
                 2ll * E[i].w * sum1[v] % P) %
                    P +
                1ll * E[i].w * E[i].w % P * (n - sz[v]) % P +
                2ll * E[i].w % P *
                    (dp1[u] - sum1[v] - 1ll * E[i].w * sz[v] % P + P + P) % P) %
               P;
    }
  }
  static int now;
  dfn[u] = ++now, top[u] = tp;
  if (son[u]) dfs2(son[u], tp);
  for (int i = h[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if (v != fa[u] && v != son[u]) dfs2(v, v);
  }
}
int qlca(int u, int v) {
  for (; top[u] != top[v]; u = fa[top[u]]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
  }
  return dep[u] < dep[v] ? u : v;
}
struct ZZH {
  int c[maxn];
  void ins(int u, int x) { Add(c[dfn[u]], x), Sub(c[dfn[u] + sz[u]], x); }
  void build() {
    for (int i = (2), iend = (n + 1); i <= iend; ++i) Add(c[i], c[i - 1]);
  }
  int query(int u, int v) { return Dec(c[dfn[u]], c[dfn[v]]); }
} B1_sz, B2_sz, B1_s1, B2_s1, B1_y, B2_y, B_w;
void solve() {
  cin >> n;
  for (int i = (2), iend = (n); i <= iend; ++i) {
    int u = read(), v = read(), w = read();
    addline(u, v, w), addline(v, u, w);
  }
  dfs1(1, 0), dp1[1] = sum1[1], dp2[1] = sum2[1], dfs2(1, 1);
  for (int i = (2), iend = (n); i <= iend; ++i) {
    B1_sz.ins(i, 1ll * dis[fa[i]] * (sz[fa[i]] - sz[i]) % P);
    B2_sz.ins(i, 1ll * dis[fa[i]] * dis[fa[i]] % P * (sz[fa[i]] - sz[i]) % P);
    int w = Dec(dis[i], dis[fa[i]]);
    B_w.ins(i, (1ll * w * w % P * sz[i] % P + 2ll * w * sum1[i] % P) % P);
    int tp = (sum1[fa[i]] - sum1[i] - 1ll * w * sz[i] % P + P + P) % P;
    B1_y.ins(i, tp);
    B2_y.ins(i, 1ll * dis[fa[i]] * tp % P);
  }
  for (int i = (1), iend = (n); i <= iend; ++i) {
    B1_s1.ins(i, sum1[i]);
    B2_s1.ins(i, 1ll * dis[i] * sum1[i] % P);
  }
  B1_sz.build(), B2_sz.build(), B_w.build();
  B1_s1.build(), B2_s1.build(), B1_y.build(), B2_y.build();
  cin >> q;
  while (q--) {
    int u = read(), v = read(), res = 0;
    if (dfn[u] < dfn[v] || dfn[u] >= dfn[v] + sz[v]) {
      int l = (dis[u] + dis[v] - 2ll * dis[qlca(u, v)] % P + P) % P;
      res = (1ll * l * l % P * sz[v] % P + 2ll * l * sum1[v] % P + sum2[v]) % P;
    } else {
      res = (sum2[v] + 1ll * dis[u] * dis[u] % P * (sz[v] - sz[u]) % P) % P;
      res =
          (res + B2_sz.query(u, v) - 2ll * dis[u] * B1_sz.query(u, v) % P + P) %
          P;
      res = (res - B_w.query(u, v) + P) % P;
      res =
          (res +
           2ll * (1ll * dis[u] * B1_y.query(u, v) % P - B2_y.query(u, v) + P) %
               P +
           P) %
          P;
    }
    res = (res * 2ll - dp2[u] + P) % P;
    printf("%d\n", res);
  }
}
signed main() {
  solve();
  return 0;
}
