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;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const long double EPS = 1e-12;
const int INF = 1e9 + 10;
const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
const int MN = 1e5 + 10;
const int MOD = 1e9 + 7;
int n, q;
vector<pair<int, int> > adj[MN], qr[MN];
int ans[MN];
long long mul[4 * MN], seg[4 * MN], lz[4 * MN];
int Time, st[MN], ft[MN];
long long d_tmp[MN];
int rev[MN];
void input() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a, --b;
    adj[a].push_back(pair<int, int>(b, c)),
        adj[b].push_back(pair<int, int>(a, c));
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    qr[u].push_back(pair<int, int>(v, i));
  }
}
void dfs_prep(int s, int pr, long long cur) {
  st[s] = Time++;
  rev[st[s]] = s;
  d_tmp[s] = cur;
  for (int i = 0; i < ((int)(adj[s]).size()); ++i) {
    int v = adj[s][i].first;
    if (v == pr) continue;
    dfs_prep(v, s, (cur + adj[s][i].second) % MOD);
  }
  ft[s] = Time;
}
void change(int segnum, int val, int left, int right) {
  int t = right - left + 1, mid = (left + right) >> 1;
  mul[segnum] = (1ll * mul[segnum] +
                 ((1ll * val * val) % MOD * (1ll * t * (t - 1) / 2)) % MOD) %
                MOD;
  mul[segnum] =
      (1ll * mul[segnum] + ((seg[segnum] * (t - 1)) % MOD * val) % MOD) % MOD;
  if (mul[segnum] < 0) mul[segnum] += MOD;
  seg[segnum] = (1ll * seg[segnum] + 1ll * val * t) % MOD;
  if (seg[segnum] < 0) seg[segnum] += MOD;
}
void shift(int segnum, int left, int right) {
  int mid = (left + right) >> 1;
  change(2 * segnum, lz[segnum], left, mid);
  change(2 * segnum + 1, lz[segnum], mid + 1, right);
  lz[2 * segnum] += lz[segnum], lz[2 * segnum + 1] += lz[segnum];
  lz[2 * segnum] %= MOD, lz[2 * segnum + 1] %= MOD, lz[segnum] = 0;
}
void build(int segnum, int left, int right) {
  if (left == right) {
    seg[segnum] = d_tmp[rev[left]];
    return;
  }
  int mid = (left + right) >> 1;
  build(2 * segnum, left, mid), build(2 * segnum + 1, mid + 1, right);
  seg[segnum] = (seg[2 * segnum] + seg[2 * segnum + 1]) % MOD;
  mul[segnum] = (mul[2 * segnum] + mul[2 * segnum + 1]) % MOD;
  mul[segnum] = (mul[segnum] + seg[2 * segnum] * seg[2 * segnum + 1]) % MOD;
}
void upd(int segnum, int left, int right, int l, int r, int val) {
  if (r < left || right < l) return;
  if (l <= left && right <= r) {
    change(segnum, val, left, right);
    lz[segnum] = (lz[segnum] + val) % MOD;
    return;
  }
  shift(segnum, left, right);
  int mid = (left + right) >> 1;
  upd(2 * segnum, left, mid, l, r, val),
      upd(2 * segnum + 1, mid + 1, right, l, r, val);
  seg[segnum] = (seg[2 * segnum] + seg[2 * segnum + 1]) % MOD;
  mul[segnum] = (mul[2 * segnum] + mul[2 * segnum + 1]) % MOD;
  mul[segnum] =
      (mul[segnum] + (seg[2 * segnum] * seg[2 * segnum + 1]) % MOD) % MOD;
}
long long get(int segnum, int left, int right, int l, int r) {
  if (r < left || right < l) return 0;
  if (l <= left && right <= r)
    return ((seg[segnum] * seg[segnum]) % MOD - (2ll * mul[segnum]) % MOD +
            MOD) %
           MOD;
  int mid = (left + right) >> 1;
  shift(segnum, left, right);
  return (get(2 * segnum, left, mid, l, r) +
          get(2 * segnum + 1, mid + 1, right, l, r)) %
         MOD;
}
void dfs(int s, int pr, int c) {
  for (int i = 0; i < ((int)(qr[s]).size()); ++i) {
    int v = qr[s][i].first;
    long long val1 = get(1, 0, n - 1, st[v], ft[v] - 1);
    long long val2 = get(1, 0, n - 1, 0, n - 1);
    ans[qr[s][i].second] = (2ll * val1 - val2 + MOD) % MOD;
  }
  for (int i = 0; i < ((int)(adj[s]).size()); ++i) {
    int v = adj[s][i].first, w = adj[s][i].second;
    if (v == pr) continue;
    upd(1, 0, n - 1, 0, n - 1, w);
    upd(1, 0, n - 1, st[v], ft[v] - 1, -2 * w);
    dfs(v, s, w);
  }
  if (pr != -1) {
    upd(1, 0, n - 1, 0, n - 1, -c);
    upd(1, 0, n - 1, st[s], ft[s] - 1, 2 * c);
  }
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
  dfs_prep(0, -1, 0);
  build(1, 0, n - 1);
  dfs(0, -1, 0);
  for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
  return 0;
}
