QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#9585. Partitioning Numbers

Estadísticas

For an integer $x$ where $x \ge 10$, it can be split into two parts as follows: Represent $x$ as a decimal string. Split the string at some position into two non-empty strings such that neither string has leading zeros. * Treat these two strings as decimal integers, denoted as $x_1$ and $x_2$.

Let $f(x)$ be the sum of the digits of $x$, and $g(x)$ be the minimum value of $|f(x_1) - f(x_2)|$ among all possible splits, where $|p|$ denotes the absolute value of $p$.

Given $l$ and $r$, calculate $\sum_{x=l}^{r} g(x)$.

Input

The input contains multiple test cases. The first line contains the number of test cases $T$ ($1 \le T \le 1000$). For each test case, the input contains two integers $l$ and $r$ ($10 \le l \le r \le 10^{18}$).

Output

For each test case, output one integer representing the sum.

Examples

Input 1

5
108 112
10 1000
10 10000
10 100000
114514 1919810

Output 1

16
3136
31636
316636
5715693

Note

For the first test case: $g(108) = |f(10) - f(8)| = |1 - 8| = 7$, $g(109) = |f(10) - f(9)| = |1 - 9| = 8$, $g(110) = \min(|f(1) - f(10)|, |f(11) - f(0)|) = \min(|1 - 1|, |2 - 0|) = 0$, $g(111) = \min(|f(1) - f(11)|, |f(11) - f(1)|) = \min(|1 - 2|, |2 - 1|) = 1$, * $g(112) = \min(|f(1) - f(12)|, |f(11) - f(2)|) = \min(|1 - 3|, |2 - 2|) = 0$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.