eolymp
bolt
Try our new interface for solving problems
Problems

Day off

Day off

Heinz Fufelschmertz has a day off today. He decided not to invent any "inator", but simply lie on the beach and drink cocktails. As a result, he dozed off in the sun and had a rather strange dream.

In the dream, there was an endless checkered field, which Heinz looked down on. There was a dice on this field. Moreover, the lower side of the cube ideally coincided with the cell of the field. If you look at the cube from above, then initially the number x1 was written on the bottom face, the number x6 on the top face, on the face looking north x2, to the south x5, west x3, east x4.

Heinz supported two values: the number s, initially equal to 0, and the direction d, initially pointing north. Then, he performed the following action several times:

  • Now let the number x be written on the top face of the cube. Heinz adds x to s. Also, x times rotates d clockwise by 90 degrees.
  • It rolls the die over the bottom edge in the direction d. Thus, the side face, which previously looked in the direction d, became the new bottom face.

When Doofenshmirtz woke up, he wondered what s could be after a few steps. Help him.

Input

The first line contains six integers x1, x2, x3, x4, x5 and x6 (* 1* ≤ xi100) - numbers written on the sides of the cube.

The second line contains an integer t (1t105) - the number of s values that Fufelschmertz is interested in.

The next t lines contain one integer qi each (1qi1018).

Output

For each number qi print "Yes" if the number s could be equal to qi as a result of several operations and "No" otherwise.

Time limit 1 second
Memory limit 128 MiB
Input example #1
1 2 3 4 5 6
4
6
8
10
14
Output example #1
Yes
Yes
No
Yes
Input example #2
1 1 1 1 1 1
2
42
12345
Output example #2
Yes
Yes
Input example #3
3 5 2 1 6 4
10
1
2
3
4
5
6
7
8
9
10
Output example #3
No
No
No
Yes
No
No
No
No
No
Yes
Source 2020 Cycle of Internet Olympiads for schoolchildren, Third team contest, Advanced level, Novemver 7, Problem J