P18506 [CodeChef] SMOL
普及-
题目描述

Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given two integers $N$ and $K$. You may perform the following operation any number of times (including zero): change $N$ to $N-K$, i.e. subtract $K$ from $N$. Find the smallest non-negative integer value of $N$ you can obtain this way.

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $N$ and $K$.

------ Output ------
For each test case, print a single line containing one integer — the smallest value you can get.

------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{9}$
$0 ≤ K ≤ 10^{9}$

------ Subtasks ------
Subtask #1 (100 points): original constraints

----- Sample Input 1 ------
3

5 2

4 4

2 5
----- Sample Output 1 ------
1

0

2
----- explanation 1 ------
Example case 1:
- First, we change $N = 5$ to $N - K = 5 - 2 = 3$.
- Then, we have $N = 3$ and we change it to $N - K = 3 - 2 = 1$.

Since $1 < K$, the process stops here and the smallest value is $1$.

Example case 2: We change $N = 4$ to $N - K = 4 - 4 = 0$. Since $0 < K$, the process stops here and the smallest value is $0$.

Example case 3: Since $2 < K$ initially, we should not perform any operations and the smallest value is $2$.

输入格式

见题面

输出格式

见题面

样例输入
3 5 2 4 4 2 5
样例输出
1 0 2