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, maxq = 5000, mod = 1e9 + 7;
int n, dfn[maxn + 10], ed[maxn + 10], dcnt;
int dep[maxn + 10], val[maxn + 10], q;
vector<pair<int, int> > ask[maxn + 10];
int ans[maxn + 10];
struct edge {
  int to, w;
};
vector<edge> g[maxn + 10];
void dfs(int p, int fa) {
  dfn[p] = ++dcnt;
  val[dcnt] = dep[p];
  for (auto i : g[p]) {
    if (i.to != fa) {
      dep[i.to] = (dep[p] + i.w) % mod;
      dfs(i.to, p);
    }
  }
  ed[p] = dcnt;
}
namespace seg {
int ls[maxn * 4 + 10], rs[maxn * 4 + 10];
int s1[maxn * 4 + 10], s2[maxn * 4 + 10], tag[maxn * 4 + 10];
void upd(int p) {
  s1[p] = (s1[p << 1] + s1[p << 1 | 1]) % mod;
  s2[p] = (s2[p << 1] + s2[p << 1 | 1]) % mod;
}
void build(int p, int l, int r) {
  ls[p] = l;
  rs[p] = r;
  if (l == r) {
    s1[p] = val[l];
    s2[p] = 1ll * val[l] * val[l] % mod;
  } else {
    int mid = (l + r) >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    upd(p);
  }
}
void apply(int p, int v) {
  int len = rs[p] - ls[p] + 1;
  (s2[p] += (1ll * v * v % mod * len + 2ll * v * s1[p]) % mod) %= mod;
  (s1[p] += 1ll * len * v % mod) %= mod;
  (tag[p] += v) %= mod;
}
void push(int p) {
  if (tag[p]) {
    apply(p << 1, tag[p]);
    apply(p << 1 | 1, tag[p]);
    tag[p] = 0;
  }
}
void modify(int p, int l, int r, int v) {
  if (ls[p] == l && rs[p] == r)
    apply(p, v);
  else {
    int mid = (ls[p] + rs[p]) >> 1;
    push(p);
    if (r <= mid)
      modify(p << 1, l, r, v);
    else if (l > mid)
      modify(p << 1 | 1, l, r, v);
    else {
      modify(p << 1, l, mid, v);
      modify(p << 1 | 1, mid + 1, r, v);
    }
    upd(p);
  }
}
int query(int p, int l, int r) {
  if (ls[p] == l && rs[p] == r)
    return s2[p];
  else {
    int mid = (ls[p] + rs[p]) >> 1;
    push(p);
    if (r <= mid)
      return query(p << 1, l, r);
    else if (l > mid)
      return query(p << 1 | 1, l, r);
    else
      return (query(p << 1, l, mid) + query(p << 1 | 1, mid + 1, r)) % mod;
  }
}
}  // namespace seg
int adj(int x) { return (x % mod + mod) % mod; }
void dfsans(int p, int fa) {
  for (auto i : ask[p]) {
    int w = i.first;
    int s1 = seg::query(1, dfn[w], ed[w]);
    int s2 = seg::query(1, 1, n);
    s2 = adj(s2 - s1);
    s2 = adj(s1 - s2);
    ans[i.second] = s2;
  }
  for (auto i : g[p]) {
    if (i.to != fa) {
      seg::modify(1, 1, n, i.w);
      seg::modify(1, dfn[i.to], ed[i.to], adj(-i.w * 2));
      dfsans(i.to, p);
      seg::modify(1, 1, n, adj(-i.w));
      seg::modify(1, dfn[i.to], ed[i.to], i.w * 2 % mod);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int l, r, w;
    scanf("%d%d%d", &l, &r, &w);
    g[l].push_back((edge){r, w});
    g[r].push_back((edge){l, w});
  }
  dfs(1, 0);
  seg::build(1, 1, n);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    ask[x].push_back(make_pair(y, i));
  }
  dfsans(1, 0);
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
}
