gWheels (Small)

Decide if any pedal gear, two distinct extra gears, and tire gear combine to each target ratio P/Q.

Easy2Brute forceMathNo attempts yetTime limit5sMemory limit512 MB

Problem

A typical mountain bike has two gear groups: one attached to the pedals and one attached to the rear tire. A gear group holds several gears whose tooth counts differ. A chain joins one gear of the pedal group to one gear of the tire group, and that choice fixes the ratio between the pedaling speed and the tire speed. For example, if the chain joins a pedal gear with 5 teeth to a tire gear with 10 teeth, the ratio is 1/21/2, because the rider turns the pedal gear twice to turn the tire once. The rider may move the chain to join any gear of the pedal group to any gear of the tire group.

You have just bought a special mountain bike with three gear groups: one on the pedals, one on the tire, and one extra group between them. This bike has two chains. The first chain must always join one gear of the pedal group to one gear of the extra group, and the second chain must always join one gear of the extra group to one gear of the tire group. The two chains cannot use the same gear of the extra group.

The ratio is the number of turns the tire makes while the pedal gear makes one turn. Given the tooth counts of the gears in the pedal, extra and tire groups, decide whether the ratio can be made exactly P/QP/Q. Several such questions are asked about one set of gears.

Input

The first line contains the number of test cases TT. The TT test cases follow.

The first line of each test case contains three integers NpN_p, NeN_e and NtN_t, the numbers of gears in the pedal, extra and tire groups. The next three lines contain NpN_p, NeN_e and NtN_t integers, the tooth counts of the gears in the pedal group, the extra group and the tire group in that order. Within one group all tooth counts are distinct. The next line contains the number of questions MM. The last MM lines each contain two integers PP and QQ, the target ratio. P/QP/Q is not guaranteed to be in lowest terms.

Output

For each test case, first print Case #x: on its own line, where x is the test case number starting from 1. Then print one line for each question of that test case, in the order the questions were given: Yes if the ratio can be made exactly P/QP/Q, and No otherwise.

Constraints

  • 1T1001 \le T \le 100
  • Each gear has at least 1 and at most 10000 teeth
  • 1P1091 \le P \le 10^9, 1Q1091 \le Q \le 10^9
  • 1M101 \le M \le 10
  • 1Np101 \le N_p \le 10, 1Nt101 \le N_t \le 10
  • 2Ne102 \le N_e \le 10

Hint

Take the first sample test case. The ratio 1/11/1 asked by the first question would need both chains on the same gear of the extra group, which is not allowed, so it is impossible.

For the second question, put the first chain on the pedal gear with 5 teeth and the extra gear with 4 teeth, and put the second chain on the extra gear with 6 teeth and the tire gear with 3 teeth. The ratio is then 5/25/2.