Given a tree with $n$ nodes. There are $m$ queries. Each query provides a set of distinct nodes $V$. You need to calculate:
- The sum of distances between all pairs of nodes in $V$, i.e., $$\sum_{u,v \in V} dis(u,v)$$
- The minimum distance between any pair of nodes in $V$, i.e., $$\min_{u,v \in V, u \neq v} dis(u,v)$$
- The maximum distance between any pair of nodes in $V$, i.e., $$\max_{u,v \in V} dis(u,v)$$
Input
The first line contains a positive integer $n$, representing the number of nodes in the tree. The next $n-1$ lines each contain two integers $u_i, v_i$, representing an edge (nodes are numbered $1, 2, 3, \dots, n$). The next line contains a positive integer $m$, representing the number of queries. For each query, the first line contains an integer $k$, representing the number of nodes in the query set; the second line contains $k$ integers in the range $[1, n]$, representing the nodes in the set.
Output
Output $m$ lines. For each query, output three integers on a single line, representing the answers in the order specified above.
Examples
Input 1
5 1 2 1 3 2 4 2 5 3 2 3 4 2 2 3 3 3 4 5
Output 1
3 3 3 2 2 2 8 2 3
Constraints
- For 20% of the data, $1 \le n, m \le 1000$;
- For another 20% of the data, $k \le 3$;
- For another 30% of the data, the tree is guaranteed to be a complete binary tree rooted at 1;
- For 100% of the data, $1 \le n, m \le 5 \times 10^5$, $2 \le k \le n$, $\sum k \le 5 \times 10^5$.