Under construction

Still being built. Things may change

Even-dominant Numbers

Time limit3sMemory limit2048 MB

Summary
For each query, count the integers x in [l, r] whose even digit count, together with the digits of floor(sqrt(x)), exceeds the odd digit count.
Level

Hard8 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Problem

This is an interactive problem.

Let xx be an even-dominant number if the total number of even decimal digits of xx and ⌊x⌋\left\lfloor \sqrt{x} \right\rfloor (the decimal representation of the square root of xx, rounded down to the nearest integer) is greater than the total number of odd decimal digits of these numbers.

For example, 222 213222\,213 is an even-dominant number because the total number of even digits in 222 213222\,213 and ⌊222 213⌋=471\left\lfloor \sqrt{222\,213} \right\rfloor = 471 is 55, which is greater than 44, the total number of odd digits. However, the number 22 is not an even-dominant number because the total number of even digits in 22 and ⌊2⌋=1\left\lfloor \sqrt{2} \right\rfloor = 1 is equal to the total number of odd digits.

Determine the number of even-dominant numbers in the segment [ℓ,r][\ell, r].

Input

The first line contains one integer tt (1≤t≤10 0001 \leq t \leq 10\,000): the number of queries.

Each of the next tt lines contains two integers ℓi\ell_i and rir_i (1≤ℓi≤ri≤10121 \leq \ell_i \leq r_i \leq 10^{12}) denoting the segment for the ii-th query.

Output

For each query, print a line with a single integer: the number of even-dominant numbers in the given segment.

Examples1

  1. Example 1

    Input
    1
    1 10
    
    Expected output
    3