QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#18321. Maximum Digit 2

統計

"When a story is about to end, we always think back to its beginning, as if everything has returned to the start."

Let $f(x)$ be the largest digit in the decimal representation of a positive integer $x$. For example, $f(4523) = 5$ and $f(1001) = 1$. Given four positive integers $l_a, r_a, l_b,$ and $r_b$ such that $l_a \le r_a$ and $l_b \le r_b$, calculate the maximum value of $f(a + b)$, where $l_a \le a \le r_a$ and $l_b \le b \le r_b$.

Ellie remembers the "easy" problem she encountered the first time she stepped onto the ICPC Asia Regional contest floor. In the blink of an eye, three full years have passed since she began her ACM career. Today, she can easily solve such introductory problems. Therefore, she decided to add a new twist to this problem that holds so many memories.

Specifically, given two positive integers $l$ and $r$ such that $l \le x \le r$, you need to:

  1. Find the maximum value of $f(x)$.
  2. Find the lexicographically smallest string $s_x$ obtained by converting $x$ to a string without leading zeros, among all $x$ that achieve the maximum value of $f(x)$.

A string $P = p_1 p_2 \dots p_x$ of length $x$ is lexicographically smaller than a string $Q = q_1 q_2 \dots q_y$ of length $y$ if: $x < y$ and $p_i = q_i$ for all $1 \le i \le x$, or There exists an integer $1 \le t \le \min(x, y)$ such that $p_i = q_i$ for all $1 \le i < t$, and $p_t < q_t$.

Input

Each test file contains multiple test cases.

The first line contains an integer $T$ ($1 \le T \le 10^5$), representing the number of test cases. For each test case:

The only line contains two integers $l$ and $r$ ($1 \le l \le r \le 10^9$).

Output

For each test case, output a single line containing two integers: the maximum value of $f(x)$ and the lexicographically smallest string $s_x$ among all $x$ that achieve this maximum value.

Examples

Input 1

4
11 17
8 39
5 27
1 2

Output 1

7 17
9 19
9 19
2 2

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.