Server Time: Sun Aug 9, 2020 5:11 am
Welcome ( logout
1108 - Instant View of Big Bang
  PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

Have you forgotten about wormholes? Oh my god! Ok, let me explain again.

A wormhole is a subspace tunnel through space and time connecting two star systems. Wormholes have a few peculiar properties:

1.      Wormholes are one-way only.

2.      The time it takes to travel through a wormhole is negligible.

3.      A wormhole has two end points, each situated in a star system.

4.      A star system may have more than one wormhole end point within its boundaries.

5.      Between any pair of star systems, there is at most one wormhole in each direction.

6.      There are no wormholes with both end points in the same star system.

All wormholes have a constant time difference between their end points. For example, a specific wormhole may cause the person traveling through it to end up 15 years in the future. Another wormhole may cause the person to end up 42 years in the past.

A brilliant physicist wants to use wormholes to study the Big Bang. Since warp drive has not been invented yet, it is not possible for her to travel from one star system to another one directly. Thiscan be done using wormholes, of course.

The scientist can start her journey from any star system. Then she wants to reach a cycle of wormholes somewhere in the universe that causes her to end up in the past. By traveling along this cycle a lot of times, the scientist is able to go back as far in time as necessary to reach the beginning of the universe and see the Big Bang with her own eyes. Write a program to help her to find such star systems where she can start her journey.


Input starts with an integer T (≤ 125), denoting the number of test cases.

Each case starts with a blank line. The next line contains two numbers n and m . These indicate the number of star systems (1 ≤ n ≤ 1000) and the number of wormholes (0 ≤ m ≤ 2000). The star systems are numbered from 0 to n-1. For each wormhole a line containing three integer numbers x, y and t is given. These numbers indicate that this wormhole allows someone to travel from the star system numbered x to the star system numbered y, thereby ending up t (-1000 ≤ t ≤ 1000) years in the future or past, a negative integer denotes past, positive integer denotes future.


For each case, print the case number first. Then print the star systems (in ascending order) where she can start her journey. If no such star system is found, print 'impossible'.

Sample Input

Output for Sample Input



3 3

0 1 1000

1 2 15

2 1 -42


4 4

0 1 10

1 2 20

2 3 30

3 0 -60

Case 1: 0 1 2

Case 2: impossible


Problem Setter: Jane Alam Jan
Developed and Maintained by
Copyright © 2012
LightOJ, Jane Alam Jan