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 long long MAX_N = 1e5 + 10, MOD = 1e9 + 7, MAX_L = 22;
long long n, q;
vector<pair<long long, long long>> adj[MAX_N];
long long sz[MAX_N], dis[MAX_N], fazir[MAX_N], fazir2[MAX_N], fabal[MAX_N],
    fabal2[MAX_N], lca[MAX_N][MAX_L + 10], fasta1[MAX_N];
void down(long long v, long long par = 0, long long w = 0) {
  sz[v] = 1;
  dis[v] = dis[par] + 1;
  fasta1[v] = (fasta1[par] + w) % MOD;
  lca[v][0] = par;
  for (long long i = 1; i < MAX_L; i++) {
    lca[v][i] = lca[lca[v][i - 1]][i - 1];
  }
  for (auto u : adj[v]) {
    if (u.first != par) {
      down(u.first, v, u.second);
      sz[v] += sz[u.first];
      fazir[v] += (((u.second * sz[u.first]) % MOD) + fazir[u.first]) % MOD;
      fazir[v] %= MOD;
      fazir2[v] += ((((u.second * u.second % MOD * sz[u.first] % MOD) +
                      fazir2[u.first]) %
                     MOD) +
                    (2 * u.second % MOD * fazir[u.first] % MOD)) %
                   MOD;
      fazir2[v] %= MOD;
    }
  }
}
void up(long long v, long long par = 0, long long w = 0) {
  if (v != 1) {
    fabal[v] =
        ((fabal[par] + (w * (n - sz[v]) % MOD)) % MOD) +
        (((fazir[par] - (((w * sz[v] % MOD) + fazir[v]) % MOD)) + MOD) % MOD);
    fabal[v] %= MOD;
    fabal2[v] = w * w % MOD * (n - sz[v]) % MOD;
    fabal2[v] %= MOD;
    fabal2[v] += fabal2[par];
    fabal2[v] %= MOD;
    fabal2[v] += 2 * w % MOD * fabal[par] % MOD;
    fabal2[v] %= MOD;
    fabal2[v] +=
        (((fazir2[par] - (((w * w % MOD * sz[v] % MOD) + fazir2[v]) % MOD +
                          (2 * w % MOD * fazir[v] % MOD)) %
                             MOD) %
          MOD) +
         MOD) %
        MOD;
    fabal2[v] %= MOD;
    fabal2[v] +=
        2 * w % MOD *
        ((((fazir[par] - (((w * sz[v] % MOD) + fazir[v]) % MOD)) % MOD) + MOD) %
         MOD);
    fabal2[v] %= MOD;
  }
  for (auto u : adj[v]) {
    if (u.first != par) {
      up(u.first, v, u.second);
    }
  }
}
long long get_par(long long v, long long k) {
  for (long long i = 0; i < MAX_L; i++) {
    if (k >> i & 1) {
      v = lca[v][i];
    }
  }
  return v;
}
long long get_lca(long long v, long long u) {
  if (dis[v] < dis[u]) {
    swap(v, u);
  }
  v = get_par(v, dis[v] - dis[u]);
  if (u == v) {
    return v;
  }
  for (long long i = MAX_L - 1; i >= 0; i--) {
    if (lca[v][i] != lca[u][i]) {
      v = lca[v][i];
      u = lca[u][i];
    }
  }
  return lca[v][0];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
  }
  dis[0] = -1;
  down(1);
  up(1);
  cin >> q;
  while (q--) {
    long long u, v, lc;
    long long ans = 0, fas;
    cin >> u >> v;
    lc = get_lca(u, v);
    fas =
        (((fasta1[v] + fasta1[u]) % MOD) - (2 * fasta1[lc] % MOD) + MOD) % MOD;
    if (lc == v) {
      ans = (((fazir2[u] + fabal2[u]) % MOD) -
             (((((fas * fas % MOD) * (n - sz[v])) % MOD) + fabal2[v] +
               ((2 * fas % MOD * fabal[v]) % MOD)) %
              MOD) +
             MOD) %
            MOD;
    } else {
      ans = ((fas * fas % MOD * sz[v]) % MOD) + fazir2[v] +
            ((2 * fas % MOD * fazir[v]) % MOD);
    }
    ans %= MOD;
    ans *= 2;
    ans %= MOD;
    ans -= ((fazir2[u] + fabal2[u]) % MOD);
    ans %= MOD;
    cout << (ans + MOD) % MOD << "\n";
  }
}
