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 MOD = 1000000007;
int N, Q;
vector<pair<int, int> > V[100002];
vector<int> W[100002];
int Q1[100002], Q2[100002];
bool S[100002];
int in[100002], out[100002], nods[100002], tn;
int D[100002];
int SUM[4 * 100002], ARB[4 * 100002], ADD[4 * 100002], A1, A2, As;
int result[100002];
void setall(int nod, int i1, int i2) {
  if (i1 == i2) {
    SUM[nod] = D[nods[i1]];
    ARB[nod] = ((long long)D[nods[i1]]) * D[nods[i1]] % MOD;
    return;
  }
  int mid = (i1 + i2) / 2;
  setall(nod * 2, i1, mid);
  setall(nod * 2 + 1, mid + 1, i2);
  ARB[nod] = (ARB[nod * 2] + ARB[nod * 2 + 1]) % MOD;
  SUM[nod] = (SUM[nod * 2] + SUM[nod * 2 + 1]) % MOD;
}
void renew(int nod, int i1, int i2) {
  ARB[nod] += ((long long)ADD[nod]) * ADD[nod] % MOD * (i2 - i1 + 1) % MOD;
  if (ARB[nod] >= MOD) ARB[nod] -= MOD;
  ARB[nod] += ((long long)ADD[nod]) * SUM[nod] * 2 % MOD;
  if (ARB[nod] >= MOD) ARB[nod] -= MOD;
  SUM[nod] += ((long long)ADD[nod]) * (i2 - i1 + 1) % MOD;
  if (SUM[nod] >= MOD) SUM[nod] -= MOD;
  if (i1 != i2) {
    ADD[nod * 2] += ADD[nod];
    if (ADD[nod * 2] >= MOD) ADD[nod * 2] -= MOD;
    ADD[nod * 2 + 1] += ADD[nod];
    if (ADD[nod * 2 + 1] >= MOD) ADD[nod * 2 + 1] -= MOD;
  }
  ADD[nod] = 0;
}
void update(int nod, int i1, int i2) {
  if (A1 <= i1 && i2 <= A2) {
    ADD[nod] += As;
    if (ADD[nod] >= MOD) ADD[nod] -= MOD;
    return;
  }
  if (ADD[nod] != 0) renew(nod, i1, i2);
  int mid = (i1 + i2) / 2;
  if (A1 <= mid) update(nod * 2, i1, mid);
  if (A2 > mid) update(nod * 2 + 1, mid + 1, i2);
  renew(nod * 2, i1, mid);
  renew(nod * 2 + 1, mid + 1, i2);
  ARB[nod] = (ARB[nod * 2] + ARB[nod * 2 + 1]) % MOD;
  SUM[nod] = (SUM[nod * 2] + SUM[nod * 2 + 1]) % MOD;
}
void query(int nod, int i1, int i2) {
  if (ADD[nod] != 0) renew(nod, i1, i2);
  if (A1 <= i1 && i2 <= A2) {
    As += ARB[nod];
    if (As >= MOD) As -= MOD;
    return;
  }
  int mid = (i1 + i2) / 2;
  if (A1 <= mid) query(nod * 2, i1, mid);
  if (A2 > mid) query(nod * 2 + 1, mid + 1, i2);
}
void Dfs(int x) {
  S[x] = true;
  in[x] = ++tn;
  nods[tn] = x;
  for (auto nod : V[x])
    if (!S[nod.first]) {
      D[nod.first] = (D[x] + nod.second) % MOD;
      Dfs(nod.first);
    }
  out[x] = tn;
}
void Prop(int x) {
  S[x] = true;
  for (auto qn : W[x]) {
    A1 = 1, A2 = N, As = 0;
    query(1, 1, N);
    result[qn] = (MOD - As) % MOD;
    A1 = in[Q2[qn]], A2 = out[Q2[qn]], As = 0;
    query(1, 1, N);
    As = 2 * As % MOD;
    result[qn] += As;
    if (result[qn] >= MOD) result[qn] -= MOD;
  }
  for (auto nod : V[x])
    if (!S[nod.first]) {
      A1 = 1, A2 = N, As = nod.second;
      update(1, 1, N);
      A1 = in[nod.first], A2 = out[nod.first],
      As = (2 * MOD - 2 * nod.second) % MOD;
      update(1, 1, N);
      Prop(nod.first);
      A1 = 1, A2 = N, As = (MOD - nod.second) % MOD;
      update(1, 1, N);
      A1 = in[nod.first], A2 = out[nod.first], As = 2 * nod.second % MOD;
      update(1, 1, N);
    }
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  for (int i = 1, nod1, nod2, val; i <= N - 1; ++i) {
    cin >> nod1 >> nod2 >> val;
    V[nod1].push_back(make_pair(nod2, val));
    V[nod2].push_back(make_pair(nod1, val));
  }
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    cin >> Q1[i] >> Q2[i];
    W[Q1[i]].push_back(i);
  }
  Dfs(1);
  setall(1, 1, N);
  memset(S, 0, sizeof(S));
  Prop(1);
  for (int i = 1; i <= Q; ++i) cout << result[i] << '\n';
}
