아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Interesting excursion

시간 제한4초메모리 제한512 MB

요약
같은 간선을 두 번 쓰지 않고 연속한 간선의 경관 유형이 다른 방향 폐보행을 찾고, 없으면 -1을 출력한다.
난이도

보통10점 중 7점

유형
그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

Flatland has nn cities, connected by mm one-directional roads.

Tourist company plans to develop a scenic cyclic tour along the roads of Flatland. This tour must start and finish at the same city, visiting some intermediate cities and traveling along some of the roads in their direction. The tour can visit some city multiple times, but it may not use the same road more than once.

Each road is characterized by the type of its landscape, which is the number from 11 to mm. To make the tour really magnificent, every two adjacent roads in the tour must have different landscape types. This also should be true for the first and the last road in the tour, so that you start to travel from any city of the tour.

Help the company to find the tour satisfying these conditions, or report that no such tour exists.

입력

Input contains multiple test cases. First line contains integer TT (1≤T≤1051 \le T \le 10^5) --- the number of test cases.

First line of each test case's description contains two integers  nn and mm (2≤n,m≤2⋅1052 \le n, m \le 2 \cdot 10^5) --- number of cities and roads. Each of next mm lines contain three integers u_iu\_i v_iv\_i c_ic\_i, meaning that ii-th road starts at city u_iu\_i, ends at city v_iv\_i and has landscape type c_ic\_i (1≤u_i,v_i≤n1 \le u\_i, v\_i \le n, 1≤c_i≤m1 \le c\_i \le m, u_i≠v_iu\_i \neq v\_i).

Sum of all nn in all test cases does not exceed 2⋅1052 \cdot 10^5. Sum of all mm in all test cases does not exceed 2⋅1052 \cdot 10^5.

출력

Output the answer of each test case.

If the desired tour does not exist, output the only number <<−1-1>>. Otherwise, print number k 2≤k≤m2 \le k \le m --- the length of the tour. In next line print kk numbers e_1,e_2,…,e_ke\_1, e\_2, \ldots, e\_k --- numbers of roads in the tour. All numbers e_ie\_i must be different. If there are multiple possible tours, output any of them.

예제1

  1. 예제 1

    입력
    3
    5 8
    1 4 1
    2 4 1
    4 5 2
    3 2 2
    5 3 1
    3 2 3
    5 2 2
    2 1 3
    4 5
    1 2 2
    2 3 1
    2 4 4
    4 1 2
    3 1 2
    2 3
    1 2 1
    1 2 2
    2 1 1
    
    예상 출력
    4
    3 5 6 2 
    -1
    2
    2 3