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

//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template< typename Monoid, typename OperatorMonoid,typename F, typename G, typename H>
struct LazySegmentTree {
  ll sz, height, n;
  vector< Monoid > data;
  vector< OperatorMonoid > lazy;
  const F f;
  const G g;
  const H h;
  Monoid M1;
  OperatorMonoid OM0;
  LazySegmentTree(ll n, const F &f,const G &g, const H &h, Monoid M1, OperatorMonoid OM0):n(n),f(f),g(g),h(h),M1(M1),OM0(OM0){
    sz = 1;
    height = 0;
    while(sz < n) sz <<= 1, height++;
    data.assign(2 * sz, M1);
    lazy.assign(2 * sz, OM0);
  }

  void set(ll k, const Monoid &x) {
    data[k + sz] = x;
  }

  void build() {
    for(ll k = sz - 1; k > 0; k--) {
      data[k] = f(data[2 * k + 0], data[2 * k + 1]);
    }
  }

  inline void propagate(ll k) {
    if(lazy[k] != OM0) {
      lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      data[k] = reflect(k);
      lazy[k] = OM0;
    }
  }

  inline Monoid reflect(ll k) {
    return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
  }

  inline void recalc(ll k) {
    while(k >>= 1) data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1));
  }

  inline void thrust(ll k) {
    for(ll i = height; i > 0; i--) propagate(k >> i);
  }

  void update(ll a, ll b, const OperatorMonoid &x) {
	if(a>=b)return;
    thrust(a += sz);
    thrust(b += sz - 1);
    for(ll l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) lazy[l] = h(lazy[l], x), ++l;
      if(r & 1) --r, lazy[r] = h(lazy[r], x);
    }
    recalc(a);
    recalc(b);
  }

  Monoid query(ll a, ll b) {
    thrust(a += sz);
    thrust(b += sz - 1);
    Monoid L = M1, R = M1;
    for(ll l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) L = f(L, reflect(l++));
      if(r & 1) R = f(reflect(--r), R);
    }
    return f(L, R);
  }

  Monoid operator[](const ll &k) {
    return query(k, k + 1);
  }

  template< typename C >
  ll find_subtree(ll a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      propagate(a);
      Monoid nxt = type ? f(reflect(2 * a + type), M) : f(M, reflect(2 * a + type));
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  ll find_first(ll a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, reflect(1)))) return find_subtree(1, check, L, false);
      return -1;
    }
    thrust(a + sz);
    ll b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, reflect(a));
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }


  template< typename C >
  ll find_last(ll b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(reflect(1), R))) return find_subtree(1, check, R, true);
      return -1;
    }
    thrust(b + sz - 1);
    ll a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(reflect(--b), R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
  void print(){
    for(ll i=0;i<n;i++)if((*this)[i]==M1)cout<<"x|";else cout<<(*this)[i]<<"|";
    cout<<endl;
  }
};
struct edge{
  ll to=-1,cost=0;
  edge(){};
  edge(ll t,ll c):to(t),cost(c){};
};
struct HLD{
  ll n, root;
  ll cnt = 0;
  vector<ll>sz;//部分木サイズ
  vector<ll>par,head;
  vector<vector<struct edge>>g;//隣接リスト
  vector<struct edge>edges;//データ構造に乗せるedge列
  vector<ll>in,out;//[in,out)で部分木、[ina,inb]でa~bのパス(aが上)
  //inは頂点のindexを表す。また、edge列の下側の頂点である
  HLD(vector<vector<struct edge>>&G,ll r = -1)
      :g(G),n(G.size()),root(r){
    par.assign(n,-1),in.assign(n,-1);
    out.assign(n,-1),head.assign(n,-1),sz.assign(n,-1);
    edges.assign(n,edge());
    dfs_build();
  }
  void dfs_build(){
    if(root == -1){//根がどこでも良い場合(森でも可)
      for(ll i=0;i<n;i++){
        if(sz[i] == -1){
          head[i] = i;
          dfs_sz(i);
          dfs_hld(i);
        }
      }
    }
    else{
      head[root] = root;
      dfs_sz(root);
      dfs_hld(root);
    }
  }
  void dfs_sz(ll k){
    sz[k] = 1;
    for(auto &e: g[k]){
      if(e.to == par[k])continue;
      par[e.to] = k;
      dfs_sz(e.to);
      sz[k] += sz[e.to];
      if(sz[e.to] > sz[g[k][0].to])swap(e, g[k][0]);
    }
  }
  void dfs_hld(ll k){
    in[k] = cnt++;
    for(auto e:g[k]){
      if(e.to == par[k])continue;
      head[e.to] = (e.to == g[k][0].to ? head[k]: e.to);
      edges[cnt] = e;
      dfs_hld(e.to);
    }
    out[k] = cnt;
  }
  ll lca(ll p,ll q){
    while(1){
      if(in[p] < in[q])swap(p,q);
      if(head[p] == head[q])return q;
      p = par[head[p]];
    }
  }
  vector<pair<ll,ll>>query_path(ll p,ll q,bool isEdge){
    ll r=lca(p,q);
    vector<pair<ll,ll>>ret;
    for(ll i=0;i<2;i++){
      if(i == 1)swap(p,q);
      while(1){
        if(isEdge&&p==r)break;
        if(head[p]==head[r]){
          ret.emplace_back(in[r]+(isEdge?1:i),in[p]+1);
          break;
        }
        ret.emplace_back(in[head[p]],in[p]+1);
        p = par[head[p]];
      }
    }
    return ret;
  }
  vector<vector<pair<ll,ll>>>query_order_path(ll p,ll q,bool isEdge){
	//非可換クエリ用、配列0を順番を反転したデータ構造に、配列1を通常のデータ構造に
    vector<vector<pair<ll,ll>>>ret(2);
    ll r=lca(p,q);
    for(ll i=0;i<2;i++){
      if(i == 1)swap(p,q);
      while(1){
        if(isEdge&&p==r)break;
        if(head[p]==head[r]){
          if(i==0) ret[i].emplace_back(n-(in[p]+1),n-(in[r]+(isEdge?1:i)));
          else ret[i].emplace_back(in[r]+(isEdge?1:i),in[p]+1);
          break;
        }
        if(i==0) ret[i].emplace_back(n-(in[p]+1),n-(in[head[p]]));
        else ret[i].emplace_back(in[head[p]],in[p]+1);
        p = par[head[p]];
      }
    }
    reverse(ret[1].begin(), ret[1].end());
    return ret;
  }
  pair<ll,ll>query_subtree(ll p,bool isEdge){
    return make_pair(in[p]+isEdge,out[p]);
  }
  //uのv方向の子 子孫関係は前もって確認すること
  ll child(ll u,ll v){
    while(1){
      if(head[u]==head[v]){
        v=g[u][0].to;
        break;
      }
      v=head[v];
      if(par[v]==u)break;
      v=par[v];
    }
    return v;
  }
};
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) += rhs;
  }
  friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) -= rhs;
  }
  friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) *= rhs;
  }
  friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) /= rhs;
  }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
using modint = ModInt< MOD1 >;modint pow(ll n, ll x){return modint(n).pow(x);}modint pow(modint n, ll x){return n.pow(x);}
//using modint=ld;
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  using A=array<modint,3>;
  auto f=[&](A x,A y){
    return A({x[0]+y[0],x[1]+y[1],x[2]+y[2]});
  };
  auto gg=[&](A x,modint y){
    return A({x[0]+2*x[1]*y+y*y*x[2],x[1]+x[2]*y,x[2]});
  };
  auto h=[&](modint x,modint y){
    return x+y;
  };
  ll n;cin>>n;
  LazySegmentTree seg(n,f,gg,h,A({0,0,0}),modint(0));
  vector<vector<edge>>g(n);
  rep(i,0,n-1){
    ll a,b,c;cin>>a>>b>>c;a--;b--;
    g[a].EB(b,c);
    g[b].EB(a,c);
  }
  HLD hld(g,0);
  ll q;cin>>q;
  vector<modint>ret(q);
  vector<vector<P>>p(n);
  rep(i,0,q){
    ll u,v;cin>>u>>v;u--;v--;
    p[u].EB(v,i);
  }
  {
    auto dfs=[&](auto &&f,ll k,ll par,ll d)->void{
      seg.set(hld.in[k],A({d*d,d,1}));
      for(auto e:g[k]){
        if(par==e.to)continue;
        f(f,e.to,k,d+e.cost);
      }
    };
    dfs(dfs,0,0,0);
  }
  seg.build();
  {
    auto sub=[&](ll k){
      auto tmp=hld.query_subtree(k,false);
      return seg.query(tmp.fi,tmp.se)[0];
    };
    auto subadd=[&](ll k,modint x){
      auto tmp=hld.query_subtree(k,false);
      seg.update(tmp.fi,tmp.se,x);
    };
    auto dfs=[&](auto &&f,ll k,ll par)->void{
      for(auto z:p[k]){
        ret[z.se]=2*sub(z.fi)-sub(0);
      }
      for(auto e:g[k]){
        if(e.to==par)continue;
        subadd(0,e.cost);
        subadd(e.to,-2*e.cost);
        f(f,e.to,k);
        subadd(0,-e.cost);
        subadd(e.to,2*e.cost);
      }
    };
    dfs(dfs,0,-1);
  }
  rep(i,0,q)cout<<ret[i]<<endl;
  return 0;
}