Hide

Problem A
Flygildaflug

Languages en is

You have decided to participate in the University of Iceland’s annual drone flying contest. Each contestant in the contest controls a drone and gets points depending on how they fly it. The drone starts on the ground (y=0) at the start line (x=0). The drone can fly up and to the right translating its location by (1,1). For doing this the contestant gets m1y+b1 points, where y denotes the height of the drone before the move is performed. The drone can also fly directly to the right translating its location by (1,0). This moves grants m2y+b2 points, where y is as before. The drone can finally, assuming it is not at the ground (y=0), fly down and to the right translating its location by (1,1). This gives m3y+b3 points, where y is as before. The points for each move that the contestant performs are then multiplied together to get the final score. The final goal is located at (N,0). The drone has to land at the goal, it does not suffice to fly over it. What is the sum of all possible scores that can be achieved?

Output

The first line of the input contains an integer 1Q104. The next line contains three integers 0m1,m2,m3109 and the third line contains three integers 109b1,b2,b3109. Finally there are Q lines, each with one integer 1N103.

Input

One line with the sum of all possible flight paths to the goal (N,0), modulo 109+7, for each N in the input.

Sample Input 1 Sample Output 1
5
1 2 1
1 1 0
2
3
4
5
6
2
6
24
120
720
Sample Input 2 Sample Output 2
5
0 1 1
1 1 0
2
3
4
5
6
2
5
15
52
203
Sample Input 3 Sample Output 3
6
1 3 2
1 1 0
2
3
4
5
6
1000
3
13
75
541
4683
581423957
Hide

Please log in to submit a solution to this problem

Log in