#P7885. KD-Graph

KD-Graph

KD-Graph

Problem Description

Let’s call a weighted connected undirected graph of nn vertices and m edges KD-Graph, if the following conditions fulfill:

  • nn vertices are strictly divided into KK groups, each group contains at least one vertice
  • if vertices pp and qq ( ppqq ) are in the same group, there must be at least one path between pp and qq meet the max value in this path is less than or equal to DD.
  • if vertices pp and qq ( ppqq ) are in different groups, there can’t be any path between pp and qq meet the max value in this path is less than or equal to DD. You are given a weighted connected undirected graph GG of nn vertices and mm edges and an integer KK. Your task is find the minimum non-negative DD which can make there is a way to divide the nn vertices into KK groups makes GG satisfy the definition of KD-Graph.Or 1-1 if there is no such DD exist.

Input

The first line contains an integer TT (1≤ TT ≤5) representing the number of test cases. For each test case , there are three integers n,m,k(2n100000,1m500000,1kn)n,m,k(2≤n≤100000,1≤m≤500000,1≤k≤n) in the first line. Each of the next mm lines contains three integers u,vu, v and cc (1v,un,vu,1c109)(1≤v,u≤n,v≠u,1≤c≤10^9) meaning that there is an edge between vertices uu and vv with weight cc.

Output

For each test case print a single integer in a new line.

Sample Input

2

3 2 2

1 2 3

2 3 5

3 2 2

1 2 3

2 3 3

Sample Output

3

-1

Source

2021“MINIEYE杯”中国大学生算法设计超级联赛(1)