P15946 [HackerEarth] Water scarcity is a major problem for Graph city. Graph city has N nodes and N - 1 edges and there is a path between every pair of nodes. Now between every pair of cities that are connec
普及-
题目描述

Water scarcity is a major problem for Graph city. Graph city has N nodes and N - 1 edges and there is a path between every pair of nodes. Now between every pair of cities that are connected there is a pipe with capacity C.

People of Graph city wanted to test the water usage. Their metric was as follows:

Given a set of cities find the pairwise sum of flows between each pair of cities in the given set. You need to answer the above query for every test set given to you.

Flow between two cities is defined as pumping water at infinite rate from one of the selected city and measuring at how much rate water comes at the other city.

All Nodes are 1 indexed.

Input

The first line contains a single integer N which is the number of cities.
Next N-1 lines describe the edges in the tree. Each line will have 3 space separated integers where the first and the second integer specify the cities between which there exists a edge and the capacity of the flow.
Next line contains a single integer Q
Next Q line contain two lines:
The first line has the number of nodes in the set and the next line has the space separated list of the nodes

Output

For each query , you need to output the pairwise sum of flow for the given set.

Constraints

1 ≤ N ≤ 10^5
1 ≤ Q ≤ 10^5
1 ≤ C ≤ 10^5
Sum of number of nodes over all queries is less than ≤ 10^5

SAMPLE INPUT
3
1 2 1
2 3 1
1
3
1 2 3

SAMPLE OUTPUT
3

输入格式

见题面

输出格式

见题面

样例输入
10 5 3 53 8 10 34 3 1 100 4 6 48 4 5 83 8 7 29 2 10 80 7 5 33 7 9 8 7 4 5 9 10 7 5 6 10 7 8 3 6 1 2 5 9 8 4 4 5 1 10 9 8 10 5 2 9 6 1 8 7 8 7 1 3 5 2 6 10 8 2 5 3
样例输出
945406 8163930 3882297 3270757 3581300 4954621 51583 17395940 4338075 710360