Under construction

Still being built. Things may change

Link-Cut Tree

Time limit2sMemory limit1024 MB

Summary
Given an undirected graph where edge i has length 2^i, find the simple cycle with the smallest total length and print its edge indices, or -1 if no cycle exists.
Level

Hard8 of 10

Topics
Graph, Union-find, Greedy
Solved
No attempts yet

Problem

BaoBao just learned how to find cycles in a graph with a data structure called link-cut tree, and decided to try it. You are given an undirected graph with nn vertices and mm edges. The length of the ii-th edge is 2i2^i. BaoBao needs to find a simple cycle with the smallest length.

A simple cycle is a subgraph that contains kk (3≤k≤n3 ≤ k ≤ n) vertices a1,a2,⋯ ,aka_1, a_2, \cdots, a_k and kk edges, such that for every 1≤i≤k1 ≤ i ≤ k there is an edge connecting aia_i and a(i mod k)+1a_{(i \bmod k)+1} in the subgraph. The length of a simple cycle is the sum of the lengths of its edges.

Input

The first line contains an integer TT, the number of test cases. Each test case is given as follows.

The first line contains two integers nn and mm (3≤n≤1053 ≤ n ≤ 10^5, 1≤m≤1051 ≤ m ≤ 10^5), the number of vertices and edges in the original graph.

The next mm lines each contain two integers uiu_i and viv_i (1≤ui,vi≤n1 ≤ u_i, v_i ≤ n), the endpoints of the edge with length 2i2^i. There are no self loops and no multiple edges. The graph is not necessarily connected.

The sum of nn over all test cases and the sum of mm over all test cases do not exceed 10610^6.

Output

For each test case, print one line. If the graph has no simple cycle, print -1. Otherwise, print the indices of the edges in the simple cycle with the smallest length, in increasing order, separated by spaces. It can be shown that there is at most one such answer.

Hint

The first test case is shown below. The number beside each edge is its index (outside the parentheses) and its length (inside the parentheses). The simple cycle with the smallest length consists of edges 22, 44, 55, and 66, with length 22+24+25+26=1162^2 + 2^4 + 2^5 + 2^6 = 116.

Examples1

  1. Example 1

    Input
    2
    6 8
    1 2
    2 3
    5 6
    3 4
    2 5
    5 4
    5 1
    4 2
    4 2
    1 2
    4 3
    
    Expected output
    2 4 5 6
    -1