#P9215. [入门赛 #11] [yLOI2021] 扶苏与 1 (Hard Version)
[入门赛 #11] [yLOI2021] 扶苏与 1 (Hard Version)
Background
The difference between this problem and the Easy Version is: the range of is different, and the length limit of is different.
Please note that the Easy Version and the Hard Version are not in a strict containment relationship.
In the contest ICPC2022 EC Final, within less than five minutes after the start, Fusu misread a problem, and turned a digit DP problem into an easy warm-up problem, completely tricking her teammates.
To avoid wasting the misread problem, it appears here.
Problem Description
Fusu gives you a number . You need to give her a number such that when performing the column addition , it produces exactly carries.
The length of your must not exceed the length of . (Note that this requirement is different from the Easy Version.)
The meaning of a carry is: in column addition, if the sum of the digits in the same column (plus any carry from the lower column) is greater than , then only the ones digit of this sum is kept in this column of the result, and we say this digit generates a carry to the higher column.
The picture below shows an example of column addition. The two digits marked in red in the result both generate carries upward.

Input Format
There are multiple groups of testdata in a single test point.
The first line contains an integer , representing the number of testdata groups.
Then follow groups of data. Each group has only two lines, with one integer per line.
The integer in the first line is .
The integer in the second line is .
Output Format
This problem uses special judge.
For each group of data, output one line with one integer, representing the you give.
If there are multiple valid , you may output any one of them. But you must satisfy the following three constraints:
- is a positive integer.
- has no leading .
- The length of does not exceed the length of .
In particular, if such a does not exist, output one line with .
5
1
1
14
1
514
2
1234
1
123456
6
9
8
516
7
877777
Hint
Constraints
For all test points, it is guaranteed that , , . The input has no leading .
Notes
The input may be very large. If , then the length of the input will not exceed . The meaning of the formula in the constraints is that will not exceed the length of .
Translated by ChatGPT 5