时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
Special Judge, 64bit IO Format: %lld

题目描述

Given a weighted connected undirected graph with n vertices and m edges, where the edge weights range from 1 to k. The weight of its minimum spanning tree (MST) is defined as the mode of the edge weights. If there are multiple numbers with the same frequency, the mode is considered to be the smallest one. Find the weight of the MST with the minimum possible mode.

Note that there may be duplicate edges or self-loops.

输入描述:

This problem has multiple sets of test data. The first line contains a positive integer T, indicating the number of sets of data.

For each set of data:
The first line contains three positive integers n, m, k.
The next m lines each contain three positive integers u, v, w, indicating an edge from u to v with weight w.

输出描述:

Output one line for each set of data, which is the answer.
示例1

输入

复制
3
5 5 3
2 1 1
3 1 2
4 3 3
5 2 2
3 4 3
5 7 3
2 1 3
3 2 2
4 1 1
5 1 2
4 5 3
1 5 3
2 5 1
5 4 3
2 1 3
3 2 3
4 1 3
5 2 2

输出

复制
2
1
3

备注:

1 \leq n , m \leq 5 \times 10^4, 1\leq u, v\leq n, 1 \leq w \leq k, \sum n, \sum m \leq 5 \times 10^4, 1 \leq k \leq 10, T \leq 5 \times 10^3.