You are given an undirected weighted graph with nodes and edges. Each edge has a weight assigned to it. You are also given an array of elements. Graph does not contain any self-loops and multiple edges.
If a new edge is added between node and , then the weight of this edge is .
Add some edges (possible 0) until there exists a subgraph such that it satisfies the following conditions:
Find the minimum possible weight of such subgraph . The weight of a graph is defined as the summation of weights of all the edges present in the graph.
Note
Input format
Output format
For each test case, print the minimum possible weight of subgraph . Print the output for each test case in a new line.
Constraints