Excellent Plan

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)局。

如果题意是这样的话,就真的简单极了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值