Under construction

Still being built. Things may change

Gunfight

Time limit1sMemory limit128 MB

Summary
Given listener based constraints on when gunshot sounds arrive, determine the unique firing order of shooters, or report impossibility or ambiguity.
Level

Medium7 of 10

Topics
Graph, Topological sort, Shortest path
Solved
No attempts yet

Problem

After a large gunfight, a trial was held to determine the order in which the shots were fired. Fortunately no one who took part was killed, but everyone's account of the firing order disagreed, and reconstructing that order is crucial to deciding guilt or innocence.

Each person's exact position is known. Every person fired at most one shot, and sound travels through the air at 340 meters per second. If a person PP fires at time tPt_P, the sound of that shot reaches a person at position QQ at time tP+d(P,Q)340t_P + \frac{d(P, Q)}{340}, where d(P,Q)d(P, Q) is the distance in meters between the two.

Each statement has the form "S1 heard S2 firing before S3", meaning that at S1's position the sound of S2's shot was heard before the sound of S3's shot, i.e. tS2+d(S1,S2)340<tS3+d(S1,S3)340t_{S2} + \frac{d(S1, S2)}{340} < t_{S3} + \frac{d(S1, S3)}{340}.

Write a program that, if firing times satisfying all statements exist and the order of the people who fired is then uniquely determined, finds that order.

Input

The first line contains the number of test cases TT (1≤T≤1001 \le T \le 100).

The first line of each test case contains the number of people nn (2≤n≤1002 \le n \le 100) and the number of statements mm (1≤m≤10001 \le m \le 1000).

Each of the next nn lines contains a person's name SS and position coordinates xx and yy. A name is at most 20 characters long and consists only of uppercase and lowercase letters. Coordinates are in meters, and no two people share the same position.

Each of the next mm lines contains one statement in the form "S1 heard S2 firing before S3". S1, S2, and S3 are names, and S2≠S3S2 \ne S3.

If a person is never mentioned as S2 or S3 in any statement, that person is assumed not to have fired.

The test data is constructed so that a distance error smaller than 10−710^{-7} does not change the answer.

Output

For each test case, print the answer on its own line. If the firing order of the people who fired is uniquely determined, print their names in firing order separated by single spaces. If more than one order is possible, print "UNKNOWN". If no order satisfies all statements simultaneously, print "IMPOSSIBLE".

Examples6

  1. Example 1

    Input
    3
    4 2
    BillyTheKid 0 0
    Andy 10 0
    John 19 0
    Larry 20 0
    Andy heard BillyTheKid firing before John
    Larry heard John firing before BillyTheKid
    2 2
    Andy 0 0
    Beate 0 1
    Andy heard Beate firing before Andy
    Beate heard Andy firing before Beate
    3 1
    Andy 0 0
    Beate 0 1
    Charles 1 3
    Beate heard Andy firing before Charles
    
    Expected output
    BillyTheKid John
    IMPOSSIBLE
    UNKNOWN
    
  2. Example 2

    Input
    1
    3 1
    Alice 0 0
    Bob 10 0
    Liam 9 0
    Liam heard Alice firing before Bob
    
    Expected output
    Alice Bob
    
  3. Example 3

    Input
    1
    2 2
    Anna 0 0
    Boris 3 4
    Anna heard Boris firing before Anna
    Boris heard Anna firing before Boris
    
    Expected output
    IMPOSSIBLE
    
  4. Example 4

    Input
    1
    3 1
    Ax 0 0
    Cx 10 0
    Bx 3 0
    Bx heard Ax firing before Cx
    
    Expected output
    UNKNOWN
    
  5. Example 5

    Input
    1
    5 2
    Ann 0 0
    Ben 100 0
    Cara 200 0
    Watch1 99 0
    Watch2 199 0
    Watch1 heard Ann firing before Ben
    Watch2 heard Ben firing before Cara
    
    Expected output
    Ann Ben Cara
    
  6. Example 6

    Input
    1
    6 3
    Ap 0 0
    Bp 10 0
    Cp 20 0
    La 9 0
    Lb 19 0
    Lc 1 0
    La heard Ap firing before Bp
    Lb heard Bp firing before Cp
    Lc heard Cp firing before Ap
    
    Expected output
    IMPOSSIBLE