402867: GYM100923 K Por Costel and the Firecracker

Memory Limit:4 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Por Costel and the Firecrackertime limit per test2 secondsmemory limit per test4 megabytesinputpocnitoare.inoutputpocnitoare.out

Pay attention to the memory limit for this probem!

One night, Por Costel the pig took a walk. He was strolling peacefully when, all of a sudden, a firecracker exploded near him. Like any pig, he had the defensive reaction of squealing horrendously and running up and down along the sidewalk. Although his movement along the sidewalk seemed random, at a closer look you can see a pattern. Let's consider the sidewalk divided into positions indexed from to . At moment , Por Costel is at position . If, at some moment , Por Costel is at position , at moment he will be at position mod . In order to be prepared for the situation in which Por Costel jumps in panic in the middle of the street (God forbid!), his fans implore you to find out where Por Costel will be at any moment. A query means "On what position will Por Costel be at moment ?" The queries will be as random as Por Costel's movement. You will first receive and the other queries will be generated using the following method: if the answer for query is , the query will be mod .

Input

In the input file pocnitoare.in you will find , , () and (Por Costel's position, ), (number of queries, ) and (first query, ).

Output

The output file pocnitoare.out should contain lines, the -th of which should contain integer (the answer to query ).

ExampleInput
17 3 7 1 3 1
Output
1
14
6

加入题单

算法标签: