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
import java.util.*;
import java.io.*;
public class D
{
	public static final long MOD = 1000000007;
	
	public static ArrayList<Edge>[] adj;
	public static long[] dist;
	public static long[] size;
	public static long[] sumb;
	public static long[] sumb2;
	public static int[] low;
	public static int[] indices;
	public static int[] depth;
	public static int index;
	public static RMQ rmq;
	public static ArrayList<Query>[] queries;
	public static long[] pathc;
	public static long[] pathc2;
	public static long[] pathbc;
	
	public static void main(String[] args) throws Exception
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = in.nextInt();
		
		adj = new ArrayList[n];
		for(int x = 0; x < adj.length; x++)
		{
			adj[x] = new ArrayList<Edge>();
		}
		
		for(int y = 0; y < n - 1; y++)
		{
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			long c = in.nextInt();
			
			adj[a].add(new Edge(b, c));
			adj[b].add(new Edge(a, c));
		}
		
		dist = new long[n];
		getDist(0, -1, 0);
		
		size = new long[n];
		getSize(0, -1);
		
		sumb = new long[n];
		getSumB(0, -1);
		
		sumb2 = new long[n];
		getSumB2(0, -1);
		
		createRMQ(0);
		
		int q = in.nextInt();
		
		queries = new ArrayList[n];
		for(int z = 0; z < queries.length; z++)
		{
			queries[z] = new ArrayList<Query>();
		}
		
		Query[] result = new Query[q];
		for(int a = 0; a < q; a++)
		{
			int u = in.nextInt() - 1;
			int v = in.nextInt() - 1;
			
			Query query = new Query(a, v);
			
			queries[u].add(query);
			result[a] = query;
		}
		
		pathc = new long[n];
		pathc2 = new long[n];
		pathbc = new long[n];
		calc(0, -1, 0, 0, 0);
		
		for(int b = 0; b < result.length; b++)
		{
			out.println(result[b].f);
		}
		
		out.close();
	}
	
	public static void getDist(int node, int parent, long d)
	{
		dist[node] = d;
		
		for(Edge e : adj[node])
		{
			if(e.end != parent)
			{
				getDist(e.end, node, (d + e.cost) % MOD);
			}
		}
	}
	
	public static long getSize(int node, int parent)
	{
		size[node] = 1;
		
		for(Edge e : adj[node])
		{
			if(e.end != parent)
			{
				size[node] += getSize(e.end, node);
			}
		}
		
		return size[node];
	}
	
	public static long getSumB(int node, int parent)
	{
		sumb[node] = dist[node];
		
		for(Edge e : adj[node])
		{
			if(e.end != parent)
			{
				sumb[node] += getSumB(e.end, node);
				sumb[node] %= MOD;
			}
		}
		
		return sumb[node];
	}
	
	public static long getSumB2(int node, int parent)
	{
		sumb2[node] = dist[node] * dist[node];
		sumb2[node] %= MOD;
		
		for(Edge e : adj[node])
		{
			if(e.end != parent)
			{
				sumb2[node] += getSumB2(e.end, node);
				sumb2[node] %= MOD;
			}
		}
		
		return sumb2[node];
	}
	
	public static void calc(int node, int parent, long sumc, long sumc2, long sumbc)
	{
		long c = size[node] * dist[node];
		c %= MOD;
		
		long c2 = c * dist[node];
		c2 %= MOD;
		
		long bc = dist[node] * sumb[node];
		bc %= MOD;
		
		long total = count((((dist[node] * dist[node]) % MOD) * size[0]) % MOD,
				sumb2[0],
				(sumc2 + c2) % MOD,
				(dist[node] * sumb[0]) % MOD,
				(dist[node] * ((sumc + c) % MOD)) % MOD,
				(sumbc + bc) % MOD);
		
		for(Query query : queries[node])
		{
			int ancestor = lca(node, query.v);
			
			long subtree = -1;
			if(ancestor != query.v)
			{
				subtree = count((((dist[node] * dist[node]) % MOD) * size[query.v]) % MOD,
						sumb2[query.v],
						(((dist[ancestor] * dist[ancestor]) % MOD) * size[query.v]) % MOD,
						(dist[node] * sumb[query.v]) % MOD,
						(dist[node] * ((dist[ancestor] * size[query.v]) % MOD)) % MOD,
						(dist[ancestor] * sumb[query.v]) % MOD);
			}
			else
			{
				subtree = count((((dist[node] * dist[node]) % MOD) * size[query.v]) % MOD,
						sumb2[query.v],
						(((sumc2 + c2 - pathc2[ancestor]) % MOD) + MOD) % MOD,
						(dist[node] * sumb[query.v]) % MOD,
						(dist[node] * ((((sumc + c - pathc[ancestor]) % MOD) + MOD) % MOD)) % MOD,
						(((sumbc + bc - pathbc[ancestor]) % MOD) + MOD) % MOD);
			}
			
			query.f = 2 * subtree;
			query.f %= MOD;
			query.f -= total;
			query.f = ((query.f % MOD) + MOD) % MOD;
		}
		
		for(Edge e : adj[node])
		{
			if(e.end != parent)
			{
				long newc = sumc + dist[node] * ((((size[node] - size[e.end]) % MOD) + MOD) % MOD);
				newc %= MOD;
				
				long newc2 = sumc2 + ((dist[node] * dist[node]) % MOD) * ((((size[node] - size[e.end]) % MOD) + MOD) % MOD);
				newc2 %= MOD;
				
				long newbc = sumbc + dist[node] * ((((sumb[node] - sumb[e.end]) % MOD) + MOD) % MOD);
				newbc %= MOD;
				
				pathc[e.end] = newc;
				pathc2[e.end] = newc2;
				pathbc[e.end] = newbc;
				
				calc(e.end, node, newc, newc2, newbc);
			}
		}
	}
	
	public static long count(long a2, long b2, long c2, long ab, long ac, long bc)
	{
		long ret = a2;
		ret %= MOD;
		ret += b2;
		ret %= MOD;
		ret += 4 * c2;
		ret %= MOD;
		ret += 2 * ab;
		ret %= MOD;
		ret -= 4 * ac;
		ret = ((ret % MOD) + MOD) % MOD;
		ret -= 4 * bc;
		ret = ((ret % MOD) + MOD) % MOD;
		
		return ret;
	}
	
	public static void createRMQ(int root)
	{
		low = new int[adj.length];
		Arrays.fill(low, -1);
		indices = new int[2 * adj.length];
		depth = new int[adj.length];
		index = 0;
		dfs(root, 0);
		
		int[] array = new int[index];
		for(int z = 0; z < index; z++)
		{
			array[z] = depth[indices[z]];
		}
		
		rmq = new RMQ(array);
	}
	
	public static void dfs(int node, int d)
	{
		low[node] = index;
		depth[node] = d;
		indices[index] = node;
		index++;
		
		for(Edge e : adj[node])
		{
			if(low[e.end] == -1)
			{
				dfs(e.end, d + 1);
				indices[index] = node;
				index++;
			}
		}
	}
	
	public static int lca(int a, int b)
	{
		if(low[a] > low[b])
		{
			int temp = a;
			a = b;
			b = temp;
		}
		
		return indices[rmq.queryIndex(low[a], low[b])];
	}
	
	static class Edge
	{
		int end;
		long cost;
		
		public Edge(int e, long c)
		{
			end = e;
			cost = c;
		}
	}
	
	static class Query
	{
		int index;
		int v;
		long f;
		
		public Query(int i, int v)
		{
			index = i;
			this.v = v;
			f = -1;
		}
	}
	
	static class RMQ
	{
		int[][][] min;
		int[][][] index;
		
		public RMQ(int[] array)
		{
			int n = array.length;
			
			int p = Integer.numberOfTrailingZeros(Integer.highestOneBit(n));
			
			min = new int[2][p + 1][n];
			index = new int[2][p + 1][n];
			
			min[0][0] = Arrays.copyOf(array, array.length);
			min[1][0] = Arrays.copyOf(array, array.length);
			
			for(int i = 0; i < array.length; i++)
			{
				index[0][0][i] = i;
				index[1][0][i] = i;
			}
			
			for(int j = 1; j < min[0].length; j++)
			{
				for(int k = 0; k < array.length; k++)
				{
					int size = 1 << (j - 1);
					
					for(int a = 0; a < 2; a++)
					{
						int next = k + (-2 * a + 1) * size;
						
						min[a][j][k] = min[a][j - 1][k];
						index[a][j][k] = index[a][j - 1][k];
						if(next >= 0 && next < n && min[a][j - 1][next] < min[a][j][k])
						{
							min[a][j][k] = min[a][j - 1][next];
							index[a][j][k] = index[a][j - 1][next];
						}
					}
				}
			}
		}
		
		public int query(int left, int right)
		{
			int p = Integer.numberOfTrailingZeros(Integer.highestOneBit(right - left + 1));
			
			return Math.min(min[0][p][left], min[1][p][right]);
		}
		
		public int queryIndex(int left, int right)
		{
			int p = Integer.numberOfTrailingZeros(Integer.highestOneBit(right - left + 1));
			
			if(min[0][p][left] <= min[1][p][right])
			{
				return index[0][p][left];
			}
			else
			{
				return index[1][p][right];
			}
		}
	}
	
	static class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		
		public FastScanner(InputStream input)
		{
			br = new BufferedReader(new InputStreamReader(input));
			st = new StringTokenizer("");
		}
		
		public String next() throws IOException
		{
			if(st.hasMoreTokens())
			{
				return st.nextToken();
			}
			else
			{
				st = new StringTokenizer(br.readLine());
				return next();
			}
		}
		
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
	}
}
