CF1488A.From Zero To Y

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

From Zero To Y

You are given two positive (greater than zero) integers xx and yy. There is a variable kk initially set to 00.

You can perform the following two types of operations:

  • add 11 to kk (i. e. assign k:=k+1k := k + 1);
  • add x10px \cdot 10^{p} to kk for some non-negative pp (i. e. assign k:=k+x10pk := k + x \cdot 10^{p} for some p0p \ge 0).

Find the minimum number of operations described above to set the value of kk to yy.

Input

The first line contains one integer tt (1t21041 \le t \le 2 \cdot 10^4) — the number of test cases.

Each test case consists of one line containing two integer xx and yy (1x,y1091 \le x, y \le 10^9).

Output

For each test case, print one integer — the minimum number of operations to set the value of kk to yy.

Note

In the first test case you can use the following sequence of operations:

  1. add 11;
  2. add 2100=22 \cdot 10^0 = 2;
  3. add 2100=22 \cdot 10^0 = 2;
  4. add 2100=22 \cdot 10^0 = 2.

1+2+2+2=71 + 2 + 2 + 2 = 7.

In the second test case you can use the following sequence of operations:

  1. add 3101=303 \cdot 10^1 = 30;
  2. add 3100=33 \cdot 10^0 = 3;
  3. add 3100=33 \cdot 10^0 = 3;
  4. add 3100=33 \cdot 10^0 = 3;
  5. add 3100=33 \cdot 10^0 = 3.

30+3+3+3+3=4230 + 3 + 3 + 3 + 3 = 42.

Samples

3
2 7
3 42
25 1337
4
5
20

在线编程 IDE

建议全屏模式获得最佳体验