Odd Cycle in a Directed Graph

Given a directed graph, decide whether it contains an odd directed cycle and output the smallest vertex of a strongly connected component that holds one.

Medium6GraphBFSDFSNo attempts yetTime limit3sMemory limit256 MB

Problem

Some problems that are hard on a general undirected graph become solvable in polynomial time once the graph has no odd cycle. To find out whether the same holds for directed graphs, you first have to decide whether a directed graph contains an odd cycle.

Let GG be a simple directed graph with no self loops and no duplicate edges. For vertices vv and ww of GG, a path from vv to ww is a sequence of vertices (u1,u2,,ul)(u_1, u_2, \dots, u_l) where the uiu_i are pairwise distinct, u1=vu_1 = v, ul=wu_l = w, and for every ii with 1i<l1 \le i < l there is a directed edge from uiu_i to ui+1u_{i+1}. If l2l \ge 2 and there is also a directed edge from ulu_l to u1u_1, the path is a cycle and ll is its length. A cycle of odd length is an odd cycle.

A strongly connected component is a maximal set of vertices that can all reach each other. Every cycle lies inside a single strongly connected component.

For each test case, decide whether the graph contains an odd cycle. If it does, also report where such a cycle sits by naming one vertex number of the strongly connected component that holds it.


Figure 1. Simple directed graphs

Input

The first line contains the number of test cases TT. (1T201 \le T \le 20)

The first line of each test case contains the number of vertices NN and the number of edges MM, separated by a space. (1N1000001 \le N \le 100\,000, 0M10000000 \le M \le 1\,000\,000) Vertices are numbered from 11 to NN.

Each of the next MM lines contains one edge in the form v w, meaning there is a directed edge from vertex vv to vertex ww. The graph is a simple directed graph, so vwv \ne w and no edge is given twice. An edge from vv to ww and an edge from ww to vv may both appear.

The sum of NN over all test cases is at most 100000100\,000, and the sum of MM over all test cases is at most 10000001\,000\,000.

Output

Print the following for each test case.

If the graph has no odd cycle, print -1 on one line.

If the graph has an odd cycle, print 1 on the first line, then on the next line print the smallest vertex number among the vertices that belong to a strongly connected component containing an odd cycle. If several such components exist, print the smallest vertex number over all of them. That vertex does not have to lie on an odd cycle itself; it only has to belong to a strongly connected component that contains one.