310769: CF1884A. Simple Design

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Simple Designtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

A positive integer is called $k$-beautiful, if the digit sum of the decimal representation of this number is divisible by $k^{\dagger}$. For example, $9272$ is $5$-beautiful, since the digit sum of $9272$ is $9 + 2 + 7 + 2 = 20$.

You are given two integers $x$ and $k$. Please find the smallest integer $y \ge x$ which is $k$-beautiful.

$^{\dagger}$ An integer $n$ is divisible by $k$ if there exists an integer $m$ such that $n = k \cdot m$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

The only line of each test case contains two integers $x$ and $k$ ($1 \le x \le 10^9$, $1 \le k \le 10$).

Output

For each test case, output the smallest integer $y \ge x$ which is $k$-beautiful.

ExampleInput
6
1 5
10 8
37 9
777 3
1235 10
1 10
Output
5
17
45
777
1243
19
Note

In the first test case, numbers from $1$ to $4$ consist of a single digit, thus the digit sum is equal to the number itself. None of the integers from $1$ to $4$ are divisible by $5$.

In the fourth test case, the digit sum of $777$ is $7 + 7 + 7 = 21$ which is already divisible by $3$.

Output

题目大意:
一个正整数如果其十进制表示的各位数字之和能被k整除,那么这个数被称为k-美丽数。例如,9272是5-美丽数,因为9272的各位数字之和是9+2+7+2=20,而20能被5整除。给定两个整数x和k,请找到大于或等于x的最小的k-美丽数。

输入输出数据格式:
输入:
第一行包含一个整数t(1≤t≤10^4),表示测试用例的数量。接下来每行包含两个整数x和k(1≤x≤10^9,1≤k≤10),描述一个测试用例。

输出:
对于每个测试用例,输出大于或等于x的最小的k-美丽数。

示例:
输入:
6
1 5
10 8
37 9
777 3
1235 10
1 10

输出:
5
17
45
777
1243
19

注意:
在第一个测试用例中,1到4的数字都是单个数字,因此它们的数字和等于数字本身。1到4中没有数字能被5整除。
在第四个测试用例中,777的数字和是7+7+7=21,21已经能被3整除。题目大意: 一个正整数如果其十进制表示的各位数字之和能被k整除,那么这个数被称为k-美丽数。例如,9272是5-美丽数,因为9272的各位数字之和是9+2+7+2=20,而20能被5整除。给定两个整数x和k,请找到大于或等于x的最小的k-美丽数。 输入输出数据格式: 输入: 第一行包含一个整数t(1≤t≤10^4),表示测试用例的数量。接下来每行包含两个整数x和k(1≤x≤10^9,1≤k≤10),描述一个测试用例。 输出: 对于每个测试用例,输出大于或等于x的最小的k-美丽数。 示例: 输入: 6 1 5 10 8 37 9 777 3 1235 10 1 10 输出: 5 17 45 777 1243 19 注意: 在第一个测试用例中,1到4的数字都是单个数字,因此它们的数字和等于数字本身。1到4中没有数字能被5整除。 在第四个测试用例中,777的数字和是7+7+7=21,21已经能被3整除。

加入题单

上一题 下一题 算法标签: