Interesting excursion
시간 제한4초메모리 제한512 MB
같은 간선을 두 번 쓰지 않고 연속한 간선의 경관 유형이 다른 방향 폐보행을 찾고, 없으면 -1을 출력한다.
문제
Flatland has cities, connected by 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 to . 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 () --- the number of test cases.
First line of each test case's description contains two integers and () --- number of cities and roads. Each of next lines contain three integers , meaning that -th road starts at city , ends at city and has landscape type (, , ).
Sum of all in all test cases does not exceed . Sum of all in all test cases does not exceed .
출력
Output the answer of each test case.
If the desired tour does not exist, output the only number <<>>. Otherwise, print number k --- the length of the tour. In next line print numbers --- numbers of roads in the tour. All numbers must be different. If there are multiple possible tours, output any of them.