Hide

Problem E
Sightseeing Tour

The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beautiful city. They want to construct the tour so that every street in the city is visited exactly once. The bus should also start and end at the same junction. As in any city, the streets are either one-way or two-way, traffic rules that must be obeyed by the tour bus. Help the executive board and determine if it’s possible to construct a sightseeing tour under these constraints.

Input

On the first line of the input is a single positive integer $n \le 20$, indicating the number of test scenarios to follow. Each scenario begins with a line containing two positive integers $m$ and $s$, $1 \le m \le 200$, $1 \le s \le 1000$ being the number of junctions and streets, respectively. The following $s$ lines contain the streets. Each street is described with three integers, $x_ i$, $y_ i$ , and $d_ i$, $1 \le x_ i, y_ i \le m$, $0 \le d_ i \le 1$, where $x_ i$ and $y_ i$ are the junctions connected by a street. If $d_ i = 1$, then the street is a one-way street (going from $x_ i$ to $y_ i$), otherwise it is a two-way street. You may assume that there exists a junction from which all other junctions can be reached.

Output

For each scenario, output one line containing the word “possible” or “impossible”, depending on whether or not it is possible to construct a sightseeing tour.

Sample Input 1 Sample Output 1
4
5 8
2 1 0
1 3 0
4 1 1
1 5 0
5 4 1
3 4 0
4 2 1
2 2 0
4 4
1 2 1
2 3 0
3 4 0
1 4 1
3 3
1 2 0
2 3 0
3 2 0
3 4
1 2 0
2 3 1
1 2 0
3 2 0
possible
impossible
impossible
possible

Please log in to submit a solution to this problem

Log in