Strange numbers
Difficulty: Hard

Let $length(A)$ denote the count of digits of a number $A$ in its decimal representation.  
John is looking for new methods of determining which numbers are strange all day long.  
All non-negative numbers of length 1 are strange. Further, a number $X$ with $length(X) \ge1$ can also be considered strange if and only if  

* $X$ is evenly divisible by $length(X)$  
* the number $X/length(X)$ is recursively strange

Your task is to calculate how many strange numbers belong to an interval $[L, R]$.  

**Input Format**  
The first line contains single integer $T$ - the number of test cases. Next $T$ lines contain two integers separated by single space $L$ and $R$.  

**Output Format**  
In $T$ lines, print $T$ integers - count of strange numbers belonging to the interval $[L, R]$.

**Constraints**  
$1 \le T \le 200$  
$0 \le L < R \le 10^{18}$  

**Sample Input**

    5
    7 25
    45 50
    1 100
    99 103
    0 1000000
    
**Sample Output**

    10
    1
    26
    0
    96
    
**Explanation**  
First testcase: There are $10$ strange numbers that belong to the interval $[7,25]$. They are $7,8,9,10,12,14,16,18,20,24$.  
Second testcase: Only $48$ satisfies the given constraints.  

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:
#
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
#  1. LONG_INTEGER l
#  2. LONG_INTEGER r
#

def solve(l, r):
    # Write your code here




Reference solution (C++):
###C++  
```cpp  
#include <iostream>
#include <vector>

using namespace std;

int t;
long long l,r;
vector<long long> V;
const unsigned long long MAX=1e+18;

int length(long long X)
{
    int sol=1;
    while (X>9){
        ++sol;
        X/=10;
    }
    return sol;
}

void precalc()
{
    V.clear();
    for(int i=0; i<10; ++i)
        V.push_back(i);

    for(int i=1; i<V.size(); ++i)
    {
        int len=length(V[i]);
        unsigned long long next=V[i]*len;

        for(int new_len=len; new_len<=len+2; ++new_len)
        {
            if (next>MAX) break;            
            int L=length(next);
            if (L>1 && length(next)==new_len) 
                V.push_back(next);
            next+=V[i];
        }

    }
}

int solve(long long L, long long R)
{
    int res=0;
    for(int i=0; i<V.size(); ++i)
        if (L<=V[i] && V[i]<=R)
            ++res;
    return res;
}

int main()
{
    precalc();
    cin >> t;
    while (t--)
    {
        cin >> l >> r;
        cout << solve(l,r) << endl;
    }

    return 0;
}
```