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.
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.