P8091 [USACO22JAN] Non-Transitive Dice B

Description

To pass the time in the barn, the cows like to play simple dice games. One such game uses two dice $X$ and $Y$. Both dice are rolled, and the die showing the larger number wins. If they show the same number, they are rolled again (as long as the rolls keep tying, the dice may be rolled multiple times). We say die $X$ beats die $Y$ if die $X$ is more likely than die $Y$ to win this game. Consider the following 4-sided dice: Die A has numbers $4$, $5$, $6$, and $7$ on its faces. Die B has numbers $2$, $4$, $5$, and $10$ on its faces. Die C has numbers $1$, $4$, $8$, and $9$ on its faces. These dice have a rather amazing property: A beats B, B beats C, and C also beats A. In particular, none of the three dice is the “best” one that can beat the other two. In this situation, when no two dice tie and no die is the best, we call the set of three dice “non-transitive”. In a non-transitive set of three dice, each die beats one of the other dice and loses to the other. Given the face values of two 4-sided dice A and B, please help the cows determine whether there is a way to assign numbers to the faces of a third die C so that the set of dice is non-transitive. All face values must be integers from $1$ to $10$.

Input Format

Each test contains multiple independent subtasks. All subtasks must be answered correctly to pass the entire test. The first line of input contains $T$ ($1 \le T \le 10$), the number of subtasks you need to solve. The next $T$ lines each describe one subtask and contain $8$ integers: the $4$ face values of die A, followed by the $4$ face values of die B. All values are between $1$ and $10$, and are not necessarily sorted. The same number may appear multiple times, even on the same die.

Output Format

Output $T$ lines. If it is possible to assign numbers to die C so that the $k$-th subtask becomes a non-transitive set of dice, output `yes` on the $k$-th line; otherwise output `no`.

Explanation/Hint

**Sample Explanation** The first subtask corresponds to the example in the statement. In the second subtask, there is no die C that can make the set non-transitive. Similarly, the answer for the third subtask is also `no`. Translated by ChatGPT 5