#P16311. [ICPC 2023 Jinan R] 最大数码

[ICPC 2023 Jinan R] 最大数码

Problem Description

Let f(x)f(x) be the largest digit in the decimal representation of a positive integer xx. For example, f(4523)=5f(4523) = 5 and f(1001)=1f(1001) = 1.

Given four positive integers lal_a, rar_a, lbl_b, and rbr_b satisfying la≤ral_a \le r_a and lb≤rbl_b \le r_b, compute the maximum possible value of f(a+b)f(a + b), where la≤a≤ral_a \le a \le r_a and lb≤b≤rbl_b \le b \le r_b.

Input Format

There are multiple testdata. The first line contains an integer TT (1≤T≤1031 \le T \le 10^3), denoting the number of test cases. For each test case:

The first line contains four integers lal_a, rar_a, lbl_b, and rbr_b (1≤la≤ra≤1091 \le l_a \le r_a \le 10^9, 1≤lb≤rb≤1091 \le l_b \le r_b \le 10^9).

Output Format

For each test case, output one integer per line, representing the maximum value of f(a+b)f(a + b).

2
178 182 83 85
2 5 3 6
7
9

Hint

For the first sample testdata, the answer is f(182+85)=f(267)=7f(182 + 85) = f(267) = 7.

For the second sample testdata, the answer is f(4+5)=f(9)=9f(4 + 5) = f(9) = 9.

Translated by ChatGPT 5