| The 2025 Asia Yokohama Regional Contest |
|---|
| Закончено |
A secret society with an undisclosed name was established in the year 1899 by a single founder, whose name is also kept secret. Subsequent members have joined the society through recommendations of existing members.
One unique rule for joining the society has been strictly enforced: Recommendations can be made by one or more existing members, but the same member group can recommend only one new member. For example, if a member was allowed to join upon the recommendation by a group of existing members $$$\{A, B, C\},$$$ no other persons can be allowed by the same recommender group. It is perfectly acceptable, however, for a group $$$\{A, B\}$$$ to recommend another new member. Although the set $$$\{A, B\}$$$ is a subset of $$$\{A, B, C\},$$$ they are distinct sets. For consistency, the group of recommenders of the founder is considered to be the empty set.
Through investigation of this secret society, you have obtained several information fragments representing some part of the membership structure of the society. Each information fragment takes one of the following forms of statements, in which the symbols $$$a, b$$$ and $$$c$$$ are integers designating certain members of the society.
The obtained information may be partial, that is, the recommendations of some members may be missing, and, moreover, there may be some members not mentioned in any of the statements.
As the information sources are not necessarily reliable, some false information might have crept in. You would like to know whether these statements are consistent, that is, whether there can be a recommendation relationship consistent with all of these statements.
The input contains one or more test cases. The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 3000$$$), which is the number of test cases. The descriptions of the $$$t$$$ test cases follow, each in the following format.
| $$$n$$$ |
| $$$s_{1}$$$ |
| $$$\vdots$$$ |
| $$$s_{n}$$$ |
The first line contains a single integer $$$n,$$$ the number of statements ($$$1 \le n \le 3000$$$). Each of the following $$$n$$$ lines is in either of the formats "recommend $$$a$$$ $$$b$$$", "not-recommend $$$a$$$ $$$b$$$", or "intersection $$$a$$$ $$$b$$$ $$$c$$$", with all of $$$a,$$$ $$$b,$$$ and $$$c$$$ being integers between $$$1$$$ and $$$3n,$$$ inclusive.
The sum of $$$n$$$'s over all the test cases does not exceed $$$3000.$$$
For each test case, output yes in one line if the situation described in the statements is possible, and output no, otherwise.
32recommend 1 2not-recommend 1 22recommend 1 2recommend 2 13intersection 1 2 2recommend 1 3not-recommend 2 3
no no no
43intersection 3 2 1recommend 3 2not-recommend 3 14intersection 1 2 3recommend 4 2recommend 4 3not-recommend 4 13intersection 3 2 1recommend 2 5intersection 3 4 55recommend 1 3not-recommend 2 3not-recommend 3 2not-recommend 1 2not-recommend 2 1
yes no yes yes
In Sample Input 1, all the test cases describe impossible situations.
The first test case of Sample Input 2 is possible. There are many possible scenarios. One example is as follows: the member $$$3$$$ is actually the founder, the member $$$2$$$ joined by the recommendation of $$$\{3\}$$$, and the member $$$1$$$ joined by the recommendation of $$$\{2\}$$$.
The last test case of Sample Input 2 is also possible. Note that it is not necessary that all the members of the society are mentioned in the information. There must be at least 4 members in the society.
| Название |
|---|


