Lavanya and Nikhil have K months of holidays ahead of them, and they want to go on exactly K road trips, one a month. They have a map of the various cities in the world with the roads that connect them. There are N cities, numbered from 1 to N. We say that you can reach city B from city A if there is a sequence of roads that starts from city A and ends at city B. Note that the roads are bidirectional. Hence, if you can reach city B from city A, you can also reach city A from city B. 
Lavanya first decides which city to start from. In the first month, they will start from that city, and they will visit every city that they can reach by road from that particular city, even if it means that they have to pass through cities that they have already visited previously. Then, at the beginning of the second month, Nikhil picks a city that they haven't visited till then. In the second month, they first fly to that city and visit all the cities that they can reach from that city by road. Then, in the third month, Lavanya identifies a city, and they fly there and visit all cities reachable from there by road. Then in the fourth month it is Nikhil's turn to choose an unvisited city to start a road trip, and they alternate like this. Note that the city that they fly to (that is, the city from where they start each month's road trip) is also considered as being visited.
Each city has some museums, and when they visit a city for the first time, Lavanya makes them visit each of the museums there. Lavanya loves going to museums, but Nikhil hates them. Lavanya always makes her decisions so that they visit the maximum number of museums possible that month, while Nikhil picks cities so that the number of museums visited that month is minimized.
Given a map of the roads, the number of museums in each city, and the number K, find the total number of museums that they will end up visiting at the end of K months. Print -1 if they will have visited all the cities before the beginning of the Kth month, and hence they will be left bored at home for some of the K months.

-----Input-----
- The first line contains a single integer, T, which is the number of testcases. The description of each testcase follows.
- The first line of each testcase contains three integers: N, M and K, which represents the number of cities, number of roads and the number of months.
- The ith of the next M lines contains two integers, ui and vi. This denotes that there is a direct road between city ui and city vi.
- The next line contains N integers, the ith of which represents the number of museums in city i.

-----Output-----
For each test case, if they can go on K road trips, output a single line containing a single integer which should be the total number of museums they visit in the K months. Output -1 if they can't go on K road trips.

-----Constraints-----
- 1 ≤ T ≤ 3
- 1 ≤ N ≤ 106
- 0 ≤ M ≤ 106
- 1 ≤ K ≤ 106
- 1 ≤ ui, vi ≤ N
- There is no road which goes from one city to itself. ie. ui ≠ vi.
- There is at most one direct road between a pair of cities.
- 0 ≤ Number of museums in each city ≤ 1000
- Sum of N over all testcases in a file will be ≤ 1.5 * 106

-----Subtasks-----
- Subtask 1 (11 points): M = 0
- Subtask 2 (21 points): Each city has at most two roads of which it is an end point. That is, for every i, there are at most two roads (u, v) in the input, such that u = i or v = i.
- Subtask 3 (68 points): Original constraints.

-----Example-----
Input:
3
10 10 3
1 3
3 5
5 1
1 6
6 2
5 6
2 5
7 10
4 7
10 9
20 0 15 20 25 30 30 150 35 20
10 10 2
1 3
3 5
5 1
1 6
6 2
5 6
2 5
7 10
4 7
10 9
20 0 15 20 25 30 30 150 35 20
10 10 5
1 3
3 5
5 1
1 6
6 2
5 6
2 5
7 10
4 7
10 9
20 0 15 20 25 30 30 150 35 20

Output:
345
240
-1

-----Explanation-----
Notice that in all the three testcases, everything is the same, except for the value of K. The following figure represents the road map in these testcases. Each node denotes a city, with a label of the form "n (m)", where n is the city number, between 1 and N, and m is the number of museums in this city.  For example, the node with label "5 (25)" represents city 5, which has 25 museums.

Testcase 1: Lavanya will first choose to fly to city 8. In the first month, they visit only that city, but they visit 150 museums.
Then in the second month, Nikhil could choose to fly to city 3, and they visit the cities 1, 2, 3, 5 and 6, and visit 20 + 0 + 15 + 25 + 30 = 90 museums that month. Note that Nikhil could have instead chosen to fly to city 1 or 2 or 5 or 6, and they would all result in the same scenario.
Then, Lavanya could choose city 7, and in the third month they will visit the cities 7, 4, 10 and 9. Note that Lavanya could have chosen to fly to city 4 or 10 or 9, and they would all result in the same scenario.
In total, they have visited 345 museums in the three months (which is in fact all the museums), and that is the answer.
Testcase 2: It is same as the previous testcase, but now they have only 2 months. So they visit only 150 + 90 = 240 museums in total.
Testcase 3: It is same as the previous testcase, but now they have 5 months of holidays. But sadly, they finish visiting all the cities within the first three months itself, and hence the answer is -1.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def merge(intervals,start,mid,end):\n al = mid-start+1\n bl = end-mid\n \n A = intervals[start:mid+1]\n B = intervals[mid+1:end+1]\n \n p=0;q=0;k=start;\n while(p<al and q<bl):\n  if(A[p]<B[q]):\n   intervals[k] = A[p]\n   k+=1;p+=1;\n  else:\n   intervals[k] = B[q]\n   k+=1;q+=1;\n \n while(p<al):\n  intervals[k] = A[p]\n  k+=1;p+=1;\n while(q<bl):\n  intervals[k] = B[q]\n  k+=1;q+=1;\n \n\ndef mergesort(intervals, start, end):\n if(start<end):\n  mid = int((start+end)/2)\n  mergesort(intervals,start,mid)\n  mergesort(intervals,mid+1,end)\n  merge(intervals,start,mid,end)\n\nt = int(input())\nfor _ in range(t):\n n,m,k = map(int, input().split())\n \n cities = [[0,[]] for i in range(n)]\n for i in range(m):\n  a,b = map(int, input().split())\n  cities[a-1][1].append(b-1)\n  cities[b-1][1].append(a-1)\n \n li = list(map(int, input().split()))\n \n def specialfunction():\n  mergesort(li,0,n-1)\n  if(k>len(li)):\n   print(-1)\n  else:\n   sum = 0\n   front = 0\n   rear = len(li)-1\n   for i in range(k):\n    if(i%2==0):\n     sum += li[rear]\n     rear -= 1\n    else:\n     sum += li[front]\n     front += 1\n   print(sum)\n \n if(m == 0):\n  specialfunction()\n  continue\n \n for i in range(n):\n  cities[i][0] = li[i]\n \n visited = [-1 for i in range(n)]\n count = 0\n museummonths = []\n def searchUnvisited():\n  for i in range(n):\n   if(visited[i] == -1):\n    return i\n  return -1\n \n def bfs(ind,count):\n  museumcount = 0\n  queue = []\n  queue.append(ind)\n  visited[ind] = 1\n  museumcount += cities[ind][0]\n  count += 1\n  front = 0\n  rear = 0\n  while(front<=rear):\n   noe = len(cities[ind][1])\n   for i in range(noe):\n    if(visited[cities[ind][1][i]] == -1):\n     queue.append(cities[ind][1][i])\n     rear += 1\n     count += 1\n     museumcount += cities[cities[ind][1][i]][0]\n     visited[cities[ind][1][i]] = 1\n   front += 1\n   try:\n    ind = queue[front]\n   except:\n    break\n  museummonths.append(museumcount)\n  return count\n \n while(count<n):\n  for i in range(n):\n   if(visited[i] == -1):\n    count = bfs(i,count)\n \n mergesort(museummonths,0,len(museummonths)-1)\n #print(museummonths)\n if(k>len(museummonths)):\n  print(-1)\n else:\n  sum = 0\n  front = 0\n  rear = len(museummonths)-1\n  for i in range(k):\n   if(i%2==0):\n    sum += museummonths[rear]\n    rear -= 1\n   else:\n    sum += museummonths[front]\n    front += 1\n  print(sum)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14153