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

import java.io.*;
import java.util.*;

public class birthday {
  private static Reader in;
  private static PrintWriter out;
  public static long mod = 1000000007;
  public static int[] eadj, eprev, elast;
  public static long[] ecost;
  public static int eidx;
  
  public static void addEdge(int a, int b, long c) {
    eadj[eidx] = b; ecost[eidx] = c; eprev[eidx] = elast[a]; elast[a] = eidx++;
    eadj[eidx] = a; ecost[eidx] = c; eprev[eidx] = elast[b]; elast[b] = eidx++;
  }
  
  private static int      root;
  private static int []   depth, queue;
  public static long[] dist;
  private static int [][] anc;
  public static int N;
  
  private static void init () {
    depth = new int[N];
    dist = new long[N];
    queue = new int[N];
    root = 0;
    anc = new int[20][N];
      Arrays.fill (depth, 1 << 29);
      
      int front = 0, back = 0;
      depth[root] = 0;
      queue[back++] = root;
      anc[0][root] = -1;
      
      while (front != back) {
          int node = queue[front++];
          for (int e = elast[node]; e != -1; e = eprev[e])
              if (depth[node] + 1 < depth[eadj[e]]) {
                  depth[eadj[e]] = depth[node] + 1;
                  dist[eadj[e]] = (dist[node] + ecost[e]) % mod;
                  anc[0][eadj[e]] = node;
                  queue[back++] = eadj[e];
              }
      }
      
      for (int k = 1; 1 << k < N; k++)
          for (int i = 0; i < N; i++)
              anc[k][i] = anc[k - 1][i] == -1 ? -1 : anc[k - 1][anc[k - 1][i]];
  }
  
  public static int before;
  
  private static int lca (int a, int b) {
      if (depth[a] < depth[b]) {
          a ^= b;
          b ^= a;
          a ^= b;
      }
      
      int diff = depth[a] - depth[b];
      for (int i = 0; 1 << i <= diff; i++)
          if (((diff) & (1 << i)) != 0)
              a = anc[i][a];
      
      if (a == b)
          return a;
      
      int log = 0;
      while (1 << (log + 1) <= depth[a])
          log++;
      
      for (int i = log; i >= 0; i--)
          if (anc[i][a] != anc[i][b]) {
              a = anc[i][a];
              b = anc[i][b];
          }
      before = a;
      return anc[0][a];
  }
  
  private static long dist (int a, int b) {
      return (dist[a] + dist[b] - 2 * dist[lca (a, b)] + 2 * mod) % mod;
  }

  public static void main(String[] args) throws IOException {
    in = new Reader();
    out = new PrintWriter(System.out, true);
    N = in.nextInt();
    eadj = new int[2*N];
    eprev = new int[2*N];
    elast = new int[N];
    ecost = new long[2*N];
    eidx = 0;
    Arrays.fill(elast, -1);
    
    for (int i = 0; i < N-1; i++) {
      int a = in.nextInt()-1, b = in.nextInt()-1;
      long c = in.nextLong();
      addEdge(a, b, c);
    }
    
    int[] queue = new int[N];
    int[] par = new int[N];
    long[] costpar = new long[N];
    int front = 0, back = 0;
    par[0] = -1;
    queue[back++] = 0;
    while (front < back) {
      int node = queue[front++];
      for (int e = elast[node]; e != -1; e = eprev[e]) {
        if (eadj[e] == par[node]) continue;
        costpar[eadj[e]] = ecost[e];
        par[eadj[e]] = node;
        queue[back++] = eadj[e];
      }
    }
    
    init();
    
    long[] sum0 = new long[N];
    for (int i = N-1; i >= 0; i--) {
      int node = queue[i];
      sum0[node] = 1;
      for (int e = elast[node]; e != -1; e = eprev[e]) {
        if (eadj[e] == par[node]) continue;
        sum0[node] += sum0[eadj[e]];
      }
    }
    
    long[] sum1 = new long[N];
    for (int i = N-1; i >= 0; i--) {
      int node = queue[i];
      sum1[node] = 0;
      for (int e = elast[node]; e != -1; e = eprev[e]) {
        if (eadj[e] == par[node]) continue;
        sum1[node] = (sum1[node] + ecost[e] * sum0[eadj[e]] + sum1[eadj[e]]) % mod;
      }
    }
    
    long[] sum2 = new long[N];
    for (int i = N-1; i >= 0; i--) {
      int node = queue[i];
      sum2[node] = 0;
      for (int e = elast[node]; e != -1; e = eprev[e]) {
        if (eadj[e] == par[node]) continue;
        long add = ecost[e] * ecost[e] % mod * sum0[eadj[e]];
        add = (add + 2 * ecost[e] * sum1[eadj[e]]) % mod;
        add = (add + sum2[eadj[e]]) % mod;
        sum2[node] = (sum2[node] + add) % mod;
      }
    }
    
    long[] up1 = new long[N];
    for (int i = 1; i < N; i++) {
      int node = queue[i];
      int p = par[node];
      
      long above = (sum1[p] + up1[p]) % mod;
      long sub = (costpar[node] * sum0[node] + sum1[node]) % mod;
      above = (above + mod - sub) % mod;
      
      long add = costpar[node] * (N - sum0[node]) % mod;
      add = (add + above) % mod;
      up1[node] = add;
    }
    
    long[] up2 =  new long[N];
    for (int i = 1; i < N; i++) {
      int node = queue[i];
      int p = par[node];
      long above = (sum2[p] + up2[p]) % mod;
      long sub = costpar[node] * costpar[node] % mod * sum0[node] % mod;
      sub = (sub + 2 * costpar[node] * sum1[node]) % mod;
      sub = (sub + sum2[node]) % mod;
      above = (above + mod - sub) % mod;
      
      long add = costpar[node] * costpar[node] % mod * (N - sum0[node]) % mod;
      add = (add + 2 * costpar[node] * (up1[p] + sum1[p] + mod - sum1[node] + (mod - costpar[node] * sum0[node] % mod))) % mod;
      add = (add + above) % mod;
      up2[node] = add;
    }
    
    int Q = in.nextInt();
    while (Q-- > 0) {
      int u = in.nextInt()-1, v = in.nextInt()-1;
      int k = lca(u, v);
      if (k == v) {
        long s1 = sum2[u];
        long a1 = (up2[u] + sum2[u]) % mod;
        
        long d1 = dist(u, v);
        long b1 = up2[u];
        long sub = d1 * d1 % mod * (N - sum0[v]) % mod;
        sub = (sub + 2 * d1 * up1[v]) % mod;
        sub = (sub + up2[v]) % mod;
        
        b1 = (b1 + mod - sub) % mod;
        s1 = (s1 + b1) % mod;
        out.println((2 * s1 + mod - a1) % mod);
      } else {
        long d1 = dist(u, v);
        long s1 = d1 * d1 % mod * sum0[v] % mod;
        s1 = (s1 + 2 * d1 * sum1[v]) % mod;
        s1 = (s1 + sum2[v]) % mod;
        long a1 = (up2[u] + sum2[u]) % mod;
        out.println((2 * s1 + mod - a1) % mod);
      }
    }
  }

  static class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
      din = new DataInputStream(System.in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
      din = new DataInputStream(new FileInputStream(file_name));
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
      byte[] buf = new byte[1024];
      int cnt = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      do {
        buf[cnt++] = c;
      } while ((c = read()) != '\n');
      return new String(buf, 0, cnt);
    }

    public String next() throws IOException {
      byte[] buf = new byte[1024];
      int cnt = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      do {
        buf[cnt++] = c;
      } while ((c = read()) > ' ');
      return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
      int ret = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      boolean neg = (c == '-');
      if (neg)
        c = read();
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');
      if (neg)
        return -ret;
      return ret;
    }

    public long nextLong() throws IOException {
      long ret = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      boolean neg = (c == '-');
      if (neg)
        c = read();
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');
      if (neg)
        return -ret;
      return ret;
    }

    public double nextDouble() throws IOException {
      double ret = 0, div = 1;
      byte c = read();
      while (c <= ' ')
        c = read();
      boolean neg = (c == '-');
      if (neg)
        c = read();
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');
      if (c == '.')
        while ((c = read()) >= '0' && c <= '9')
          ret += (c - '0') / (div *= 10);
      if (neg)
        return -ret;
      return ret;
    }

    private void fillBuffer() throws IOException {
      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      if (bytesRead == -1)
        buffer[0] = -1;
    }

    private byte read() throws IOException {
      if (bufferPointer == bytesRead)
        fillBuffer();
      return buffer[bufferPointer++];
    }

    public void close() throws IOException {
      if (din == null)
        return;
      din.close();
    }
  }


}
