Saturday 16 May 2020

Codeforces Round #643 (Div. 2) : Sequence with Digits : Solution in python

A. Sequence with Digits


time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Let's define the following recurrence:

Here

and are the minimal and maximal digits in the decimal representation of

without leading zeroes. For examples refer to notes.

Your task is calculate

for given and

.

Input

The first line contains one integer

(

) — the number of independent test cases.

Each test case consists of a single line containing two integers

and (,

) separated by a space.

Output

For each test case print one integer

on a separate line.

Example
Input
Copy
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
Copy
42
487
519
528
544
564
588
628
Note

No comments:

Post a Comment