Time limit
1s
Memory limit
128 MB
There are three kinds of weights: A-gram weights, B-gram weights, and 1-gram weights. A and B are distinct positive real numbers. You are given several experiment results, and each result only records a case where the two-pan balance tilted to the left or to the right.
For each requested comparison, determine which side must be heavier using only the given experiment results, without using the balance again.
Consider these two observed results.
The first result means that two B-gram weights on the left were lighter than two A-gram weights, one B-gram weight, and two 1-gram weights on the right. The second result means that two A-gram weights, one B-gram weight, and two 1-gram weights on the left were heavier than three A-gram weights and three 1-gram weights on the right.
From these two results, comparing [A] with [B, 1] always gives [A] < [B, 1].
However, some comparisons cannot be determined. If the only known result is [A, A] < [B, B, B] and the requested comparison is [A] versus [B], both [A] > [B] and [A] < [B] are possible, so the answer is unknown.
The first line contains an integer K, the number of balance experiments. 1 ≤ K ≤ 10.
Each of the next K lines contains one experiment result. The weights placed on the left and right sides are listed with spaces between them, and the two sides are separated by either > or < to show the tilt direction. Each line ends with $.
The final five lines contain the comparisons to decide, one per line. The weights on each side are listed with spaces between them, and the left and right sides are separated by |. Each of these lines also ends with $.
At most 1000 weights can be placed on one side of the balance.
Print one answer line for each of the five comparisons.
Print > if the left side must be heavier, < if the right side must be heavier, and ? if the given experiment results are not enough to decide. The requested comparison is never balanced in the actual situation.