#P15079. [ICPC 2024 Chengdu R] Friendship is Magic
[ICPC 2024 Chengdu R] Friendship is Magic
题目描述
Rockdu is a pony living in Ponyville. His best friend, Macaronlin, also lives there. Rockdu values friendship so much that he shares everything with Macaronlin, even integers.
Here comes the question: how to share an integer with someone else? For an integer , Rockdu splits it into two parts. Specifically, he treats in decimal form as a string without leading zeros, and splits it into two non-empty substrings at a certain position. He then considers these two substrings as two separate decimal integers, denoted as (the former) and (the latter).
Rockdu wants and to be as close in value as possible. Therefore, among all possible splits, he chooses the one that minimizes the absolute difference between and . For example, if , there are three possible ways to split it: , , and . Rockdu chooses the first way because it yields the smallest absolute difference: , whereas the other ways give and .
Let be defined as the smallest absolute difference between the two integers resulting from splitting . For example, . Given two integers and , Rockdu wants to calculate the sum of for all in the range . Since the answer may be very large, please output it modulo .
输入格式
The first line contains an integer (), indicating the number of test cases.
Each test case contains two integers () in a single line.
输出格式
For each test case, output the answer modulo in a single line.
2
108 112
114514 1919810
31
86328270
提示
For the first test case in the sample:
Therefore, .