Under construction

Still being built. Things may change

Degree of Spanning Tree

Time limit3sMemory limit512 MB

Summary
Given a connected graph, find a spanning tree in which every vertex has degree at most n/2, or report that no such tree exists.
Level

Medium7 of 10

Topics
Graph, Tree, DFS
Solved
No attempts yet

Problem

You are given an undirected connected graph with nn vertices and mm edges. Find a spanning tree of the graph such that every vertex in the tree has degree at most n2\frac{n}{2}.

The degree of a vertex is the number of edges connected to it.

Input

The first line contains an integer TT, the number of test cases. For each test case:

The first line contains two integers nn and mm (2≤n≤1052 \le n \le 10^5, n−1≤m≤2×105n-1 \le m \le 2 \times 10^5), the number of vertices and edges.

The next mm lines each contain two integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n), meaning there is an edge between vertices uiu_i and viv_i. The graph may contain self loops and multiple edges.

The graph is guaranteed to be connected. The sum of nn over all test cases does not exceed 5×1055 \times 10^5, and the sum of mm does not exceed 10610^6.

Output

For each test case, if a valid spanning tree exists, print "Yes" on one line. Then print n−1n-1 lines, each with two integers pip_i and qiq_i, meaning the tree contains an edge between pip_i and qiq_i.

If no valid spanning tree exists, print "No" on one line.

Hint

In the first sample, the maximum degree in the spanning tree is 3 (vertices 1 and 4 both have degree 3). Since 3≤623 \le \frac{6}{2}, the answer is valid.

In the second sample, every spanning tree has a vertex with degree 2. Since 2>322 > \frac{3}{2}, no valid answer exists.

Examples1

  1. Example 1

    Input
    2
    6 9
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    4 5
    4 6
    4 6
    3 4
    1 3
    2 3
    3 3
    1 2
    
    Expected output
    Yes
    1 2
    1 3
    1 4
    4 5
    4 6
    No