#P15079. [ICPC 2024 Chengdu R] Friendship is Magic

[ICPC 2024 Chengdu R] Friendship is Magic

Problem Description

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 xx, Rockdu splits it into two parts. Specifically, he treats xx 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 x1x_1 (the former) and x2x_2 (the latter).

Rockdu wants x1x_1 and x2x_2 to be as close in value as possible. Therefore, among all possible splits, he chooses the one that minimizes the absolute difference between x1x_1 and x2x_2. For example, if x=1003x = 1003, there are three possible ways to split it: 1∣0031|003, 10∣0310|03, and 100∣3100|3. Rockdu chooses the first way because it yields the smallest absolute difference: ∣1−3∣=2|1 - 3| = 2, whereas the other ways give ∣10−3∣=7|10 - 3| = 7 and ∣100−3∣=97|100 - 3| = 97.

Let f(x)f(x) be defined as the smallest absolute difference between the two integers resulting from splitting xx. For example, f(1003)=2f(1003)=2. Given two integers ll and rr, Rockdu wants to calculate the sum of f(i)f(i) for all ii in the range [l,r][l, r]. Since the answer may be very large, please output it modulo 109+710^9 + 7.

Input Format

The first line contains an integer TT (1≤T≤10001 \le T \le 1000), indicating the number of test cases.

Each test case contains two integers l,rl,r (10≤l≤r≤101810 \le l \le r \le 10^{18}) in a single line.

Output Format

For each test case, output the answer modulo 109+710^9+7 in a single line.

2
108 112
114514 1919810
31
86328270

Hint

For the first test case in the sample:

  • f(108)=min⁡(∣1−8∣,∣10−8∣)=min⁡(7,2)=2f(108)=\min(|1-8|,|10-8|)=\min(7,2)=2
  • f(109)=min⁡(∣1−9∣,∣10−9∣)=min⁡(8,1)=1f(109)=\min(|1-9|,|10-9|)=\min(8,1)=1
  • f(110)=min⁡(∣1−10∣,∣11−0∣)=min⁡(9,11)=9f(110)=\min(|1-10|,|11-0|)=\min(9,11)=9
  • f(111)=min⁡(∣1−11∣,∣11−1∣)=min⁡(10,10)=10f(111)=\min(|1-11|,|11-1|)=\min(10,10)=10
  • f(112)=min⁡(∣1−12∣,∣11−2∣)=min⁡(11,9)=9f(112)=\min(|1-12|,|11-2|)=\min(11,9)=9

Therefore, ∑i=108112f(i)=2+1+9+10+9=31\sum_{i=108}^{112}f(i)=2+1+9+10+9=31.