P16510 [CodeChef] DIGITREM
提高-
题目描述

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

You are given an integer N and a digit D. Find the minimum non-negetive integer you should add to N such that the final value of N does not contain the digit D.

------ Input Format ------

  • The first line contains T denoting the number of test cases. Then the test cases follow.
  • Each test case contains two integers N and D on a single line denoting the original number and the digit you need to avoid.

------ Output Format ------

For each test case, output on a single line the minimum non-negetive integer you should add to N.

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{9}$
$0 ≤ D ≤ 9$

------ subtasks ------

Subtask 1 (100 points): Original constraints

----- Sample Input 1 ------
5
21 5
8 8
100 0
5925 9
434356 3

----- Sample Output 1 ------
0
1
11
75
5644

----- explanation 1 ------
Test case $1$: $N = 21$ does not contain the digit $D = 5$. Hence there is no need to add any integers to $N$.

Test case $2$: If $1$ is added to $N = 8$, it becomes equal to $9$, which does not contain the digit $D = 8$.

Test case $3$: The minimum integer you should add to $N = 100$ such that the final value of $N$ does not contain the digit $D = 0$ is $11$.

Test case $5$: The minimum integer which is greater than $434356$ and does not contain the digit $D = 3$ is $440000$. So we should add $440000 - 434356 = 5644$.

输入格式

见题面

输出格式

见题面

样例输入
5 21 5 8 8 100 0 5925 9 434356 3
样例输出
0 1 11 75 5644