Timer is Running

Minimum Notes Required
Submissions: 987   Accuracy:


  Difficulty: Easy   Marks: 2

John works in RS Software and today he is supposed to receive his salary. RS Software pays its employees in cash. However, John's wallet has one drawback. His wallet can contain no more than M notes or coins. Taking his case into consideration, his boss pays him his salary by the minimum notes possible. However John may have to leave out some money. Tell John how much money will he have to lose.
Note: The values of notes or coins available are 1000, 500, 100, 50, 20, 10, 5, 2 and 1.

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of a single line containing two space separated integers N and M denoting John's salary and the maximum number of notes his wallet can hold, respectively.

Corresponding to each test case, print the desired output in a single line.

1 <= T <= 100
1 <= N <= 100000
1 <= M <= 1000

1712 4
1023 2
2341 3


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arpan Kundu
Author: akundusaltlake

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.