King & Weber

No attempts yetTime limit1sMemory limit128 MB

Problem

It is easy to get lost in Kitchener-Waterloo. Many streets that look mostly parallel actually intersect one another, sometimes multiple times. The best-known example is King Street and Weber Street. Other examples include Westmount and Fischer-Hallman, University and Erb, and Queen and Highland.

Navigation is easier in cities that respect the "Manhattan Assumption": every street is a straight line in the Euclidean plane, and any two streets are either parallel or perpendicular to each other. (Note that even Manhattan itself does not fully satisfy this assumption.)

The input describes one particular city as a sequence of observations followed by a sequence of queries. Each observation asserts either that two streets are parallel or that they intersect. Each query asks whether two streets must be parallel or must intersect, assuming the city satisfies the Manhattan Assumption.

Input

The first line contains two integers $m$ and $n$ ($1 \le m, n \le 100000$).

Each of the next $m$ lines contains one observation: three space-separated words, namely the two street names followed by the word parallel or the word intersect.

Each street name is a string of at most 100 uppercase or lowercase English letters, and names are case-sensitive.

The observations are followed by $n$ queries, each on its own line. Each query consists of two street names separated by a space.

Output

If it is impossible for the city to satisfy both the Manhattan Assumption and all of the given observations, output a single line containing the word Waterloo.

Otherwise, output $n$ lines with the answers to the $n$ queries. Each answer is one of the three words parallel, intersect, or unknown:

  • Output parallel if the two queried streets are parallel in every city that satisfies the observations and the Manhattan Assumption.
  • Output intersect if they are perpendicular in every such city.
  • Output unknown if they are parallel in some such city and perpendicular in another.