10
5 1 33242121
5 7 535463871
9 1 202863787
5 4 874413088
6 1 623012241
6 8 786659185
10 5 164281028
9 2 851489092
3 9 169897037
10
9 7
7 7
5 9
6 1
3 6
6 5
2 3
7 7
8 9
7 2
 10
3 1 278114804
3 7 453886464
8 7 830020662
8 2 759298564
9 2 147615930
2 4 617310668
10 2 921400635
2 5 185694079
6 2 157439659
10
4 3
7 7
9 4
2 4
4 1
6 3
7 2
1 10
4 5
1 9
 10
3 1 278114804
3 7 453886464
8 7 830020662
8 2 759298564
9 2 147615930
9 4 617310668
10 4 921400635
4 5 185694079
6 4 157439659
10
4 3
7 7
9 4
2 4
4 1
6 3
7 2
1 10
4 5
1 9
 10
3 1 940484348
1 2 683105297
6 1 34326471
6 7 846216720
10 3 913688945
6 5 62114151
4 2 895808279
3 9 73879870
8 10 274103932
10
10 6
5 8
3 5
7 10
6 6
2 4
1 5
6 4
8 6
9 10
 10
3 1 278114804
1 7 453886464
8 1 830020662
1 2 759298564
9 1 147615930
1 4 617310668
10 1 921400635
1 5 185694079
6 1 157439659
10
4 3
7 7
9 4
2 4
4 1
6 3
7 2
1 10
4 5
1 9
 10
7 1 948825254
7 8 163731103
5 7 24781877
1 9 873109737
6 5 922157259
6 4 695796614
3 8 710123832
5 2 229846714
10 2 126680384
10
1 6
3 7
2 1
10 4
5 1
9 9
10 8
4 2
7 3
1 8
 10
3 1 278114804
3 7 453886464
8 7 830020662
8 2 759298564
9 2 147615930
9 4 617310668
10 4 921400635
10 5 185694079
6 5 157439659
10
4 3
7 7
9 4
2 4
4 1
6 3
7 2
1 10
4 5
1 9
 10
3 1 278114804
3 7 453886464
8 1 830020662
8 2 759298564
9 1 147615930
9 4 617310668
10 1 921400635
10 5 185694079
6 1 157439659
10
4 3
7 7
9 4
2 4
4 1
6 3
7 2
1 10
4 5
1 9

754602117
941306036
345159140
889751864
221567087
452330243
610417136
941306036
595859331
524414191
 154209178
787444642
453508248
220845981
811407029
585833802
738688277
482446523
570228330
938497929
 153593825
962975972
258291347
478762666
561612109
329362801
914219607
371538245
906952313
964451612
 799905193
189641085
247256971
16810814
597350254
995209118
212122928
806020836
286406008
266027678
 249228255
490830292
244045360
106498909
338602533
608288211
212101232
448454413
43032819
251819024
 307488562
936965007
669306706
472217029
103977612
445047045
340459197
439153232
484754007
867070884
 859089925
583743823
284988364
199943666
267108202
191221580
534987458
420592815
717499524
997368329
 203173178
722185173
839677047
956076405
781508643
309964349
11590066
259439789
320401300
152672030

#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X abs(const X& a) {
  return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
  return a * a;
}
const int INF = int(1e9);
const long long INF64 = long long(1e18);
const long double EPS = 1e-9, PI = 3.1415926535897932384626433832795;
const int N = 100 * 1000 + 3;
const int mod = 1000 * 1000 * 1000 + 7;
const int LOGN = 20;
int n, m;
vector<int> g[N], w[N];
pair<int, int> q[N];
inline bool read() {
  if (!(cin >> n)) return false;
  for (int i = 0; i < int(n - 1); i++) {
    int first, second, c;
    assert(scanf("%d%d%d", &first, &second, &c) == 3);
    first--, second--;
    g[first].push_back(second), w[first].push_back(c);
    g[second].push_back(first), w[second].push_back(c);
  }
  cin >> m;
  for (int i = 0; i < int(m); i++) {
    assert(scanf("%d%d", &q[i].first, &q[i].second) == 2);
    q[i].first--, q[i].second--;
  }
  return true;
}
int add(int a, int b) { return (a + b >= mod) ? (a + b - mod) : (a + b); }
int add(int a, int b, int c) { return add(a, add(b, c)); }
int sub(int a, int b) { return add(a, mod - b); }
int mul(int a, int b) { return int((a * 1ll * b) % mod); }
int mul(int a, int b, int c) { return mul(a, mul(b, c)); }
int cnt[N];
int d[N];
int p[LOGN][N];
int s1[N], s2[N];
int T, tin[N], tout[N];
void dfs(int v, int pr, int w) {
  tin[v] = T++;
  p[0][v] = pr;
  for (int i = 1; i <= int(LOGN - 1); i++) p[i][v] = p[i - 1][p[i - 1][v]];
  d[v] = add(d[pr], w);
  cnt[v] = 1;
  for (int i = 0; i < int(int((g[v]).size())); i++) {
    int to = g[v][i];
    if (to == pr) continue;
    int W = ::w[v][i];
    dfs(to, v, W);
    cnt[v] += cnt[to];
    s1[v] = add(s1[v], s1[to], mul(cnt[to], W));
    s2[v] = add(s2[v], s2[to], add(mul(2, W, s1[to]), mul(cnt[to], W, W)));
  }
  tout[v] = T++;
}
bool parent(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
int lca(int a, int b) {
  if (parent(a, b)) return a;
  if (parent(b, a)) return b;
  for (int i = int(LOGN) - 1; i >= 0; i--)
    if (!parent(p[i][a], b)) a = p[i][a];
  return p[0][a];
}
int S[N];
int pos[N];
vector<pair<int, pair<int, int> > > z[N];
void dfs(int v, int pr, int cup, int up1, int up2, int idx) {
  S[v] = add(up2, s2[v]);
  pos[v] = idx;
  for (int i = 0; i < int(int((g[v]).size())); i++) {
    int to = g[v][i];
    if (to == pr) continue;
    int W = w[v][i];
    int cdw = sub(cnt[v], cnt[to]);
    int dw1 = sub(s1[v], add(s1[to], mul(cnt[to], W)));
    int dw2 =
        sub(s2[v], add(s2[to], add(mul(2, W, s1[to]), mul(cnt[to], W, W))));
    z[v][i] = make_pair((cdw), (make_pair((dw1), (dw2))));
    int ncup = add(cup, cdw);
    int nup1 = add(up1, dw1);
    int nup2 = add(up2, dw2);
    nup2 = add(nup2, mul(2, W, nup1), mul(ncup, W, W));
    nup1 = add(nup1, mul(ncup, W));
    dfs(to, v, ncup, nup1, nup2, i);
  }
}
inline void solve() {
  for (int i = 0; i < int(n); i++)
    z[i] = vector<pair<int, pair<int, int> > >(int((g[i]).size()));
  T = 0;
  dfs(0, 0, 0);
  dfs(0, -1, 0, 0, 0, -1);
  for (int i = 0; i < int(m); i++) {
    int u = q[i].first;
    int v = q[i].second;
    int l = lca(u, v);
    int d = ::d[u] + ::d[v] - 2 * ::d[l];
    int ans;
    if (!parent(v, u)) {
      int S1 = add(s2[v], mul(2, d, s1[v]), mul(cnt[v], d, d));
      ans = sub(mul(2, S1), S[u]);
    } else {
      int S2 = 0;
      if (v != 0) {
        int pr = p[0][v], idx = pos[v];
        int cnt = z[pr][idx].first;
        int s1 = z[pr][idx].second.first;
        int s2 = z[pr][idx].second.second;
        d = add(d, sub(::d[v], ::d[pr]));
        S2 = add(s2, mul(2, d, s1), mul(cnt, d, d));
      }
      ans = sub(S[u], mul(2, S2));
    }
    printf("%d\n", ans);
  }
}
inline void clear() {
  memset(cnt, 0, sizeof(cnt));
  memset(d, 0, sizeof(d));
  memset(p, 0, sizeof(p));
  memset(s1, 0, sizeof(s1));
  memset(s2, 0, sizeof(s2));
  memset(S, 0, sizeof(S));
}
int main() {
  cout << setprecision(10) << fixed;
  cerr << setprecision(5) << fixed;
  clear();
  assert(read());
  solve();
  return 0;
}
