Mr. AngelClover is fond of Neokart which is a kind of racing game on PC, and he spends much time on it. As Mr. AngelClover wants a high score in this game, he has to play as many rounds as possible. To get this target, he decides to play X times the number of rounds he played the day before. However, he doesn't want to get too addicted in it to affect his study. He modifies his plan that the number of rounds he has to play one day should be the remainder after divided by a certain number M. i.e. he would never play more than M rounds on a single day. Please help him to calculate how many rounds he would play on the Nth day.
Input (Please use standard input, and don’t read or write files.) | |
First line contains one number T T lines followed, and each contains four integers A, X, M, N. A is the number of rounds he played on the first day. X, M, N are as described above. 0< T <=1000, 0< A < 100, 0< X <231, 0< M <10000, 0< N < 231
| |
Output (Please use standard output, and don’t read or write files.) | |
Output T lines and each contains an integer which is the number of rounds he will play on the Nth day | |
| |
Sample Input | Sample Output |
1 99 100 9999 5 | 99
|
题意?:假设第N-1天玩了Y局,则第N天玩了M%(X*Y)局。
如果题意是这样的话,就真的简单极了。