#P10697. [SNCPC2024] 消失的数字
[SNCPC2024] 消失的数字
Problem Description
uuku is learning digit DP.
But one day, he found that among the nine digits , the digit disappeared. That is, all numbers that contain the digit disappeared.
This made him very nervous, because it has a big impact on counting how many numbers there are.
Now, he wants you to help him find the rank of the number among the natural numbers that did not disappear, when ordered from small to large.
Input Format
This problem has multiple test cases. The first line contains an integer (), which indicates the number of test cases.
For each test case:
There is one line with two integers (), separated by a space, with meanings as described in the statement.
The testdata guarantees that does not contain the digit .
Output Format
For each test case, output one integer per line, which is the rank of .
5
9 4
99 7
12345678 9
9475632111234123 8
998244353114514 7
9
81
6053445
1758041005111510
205404686678741
Hint
For the first test case in the sample, the sequence of natural numbers becomes , where is the -th.
Translated by ChatGPT 5