Question: Write code in python to solve the problem Input Format Each test contains several lines: Line 1: Four integers: x, a, b, m Line 2:

Write code in python to solve the problem

Input Format

Each test contains several lines:

Line 1: Four integers: x, a, b, m

Line 2: A single integer, q, indicating the number of queries

Each of the subsequent q lines contains a single integer denoting a value of n.

Output Format

For each value of n, output on a separate line, a single integer indicating the final position of the ball after n kicks.

Sample Input

1 2 3 10

1

2

Sample Output

1

Explanation

The wheel is marked with 10 positions (numbered clockwise from 0 to 9). The ball starts in position 1, and we want to know where it ends up after 2 kicks. On the first kick, it advances (clockwise) 2 positions (because a=2) once (because its current position at the time of the kick was 1) and then finally by 3 positions (because b=3) to end up at position 1+2+3=6. On the second kick, it advances 2 positions 6 times (i.e. from position 6 to positions 8, 0, 2, 4, 6, 8) and then 3 more positions to finally stop at position 1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!