PRB3: Rumor // Beginner

 

Fallon promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Fallon started playing it.

Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.

Fallon knows that there are characters in Overcity. Some characters are friends to each other, and they share information they got. Also, Fallon knows that he can bribe each character so that he or she starts spreading the rumor; the character wants gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.

The quest is finished when all characters know the rumor. What is the minimum amount of gold Fallon needs to spend in order to finish the quest?

Input Format

The first line contains the number of test cases, .

In each test case:

The first line contains two integer numbers and (, ) — the number of characters in Overcity and the number of pairs of friends.

The second line contains integer numbers () — the amount of gold that the character asks for to start spreading the rumor.

Then lines follow, each containing a pair of numbers which represent that characters and are friends (). It is guaranteed that each pair is listed at most once.

Sample Input

1
5 2
2 5 3 4 8
1 4
4 5

Output Format

For each test case, print one number — the minimum amount of gold Fallon has to spend in order to finish the quest.

Sample Output

10

Show Hints


You must be logged in to submit a solution.