Uppal's Ego
Difficulty: Hard

Ramu is very good at maths. He always tries to play with different kinds of numbers. This time he has discovered a new type of numbers and has named them **KMH** numbers. According to him, a number **N** is a **KMH** number, if **the sum of its prime divisors is a power of 2** i.e **_(2, 4, 8, ...and so on)._**         
**Example:**  
**1. 15= 3 X 5**  
prime divisors 3,5   
sum = 3 + 5 = 8  
**2. 3025 = 5<sup>2</sup> X 11<sup>2</sup>**  
prime divisors 5,11  
sum = 5 + 11 = 16
  
So **15**, **3025** are some **KMH numbers**.

Uppal is Ramu’s roommate and Ramu challenges him to do a task related to **KMH** numbers. Uppal will be given 2 integers **A,B** and asked to tell **the number of integers between A and B (inclusive) whose "Sum of digits" is a KMH number**. Uppal takes every lose to his ego . So he has asked your help so that he can answer all queries asked by Ramu. Help Uppal so that his ego doesn't get hurt.

**Example**   
**44**   
sum of digits : 4 + 4 = 8   
8 = 2<sup>3</sup>   
sum of prime divisors = 2.   
So **44** is a number whose sum of digits is a **KMH** number.

###**INPUT FORMAT**   
First line contains number of test cases **T**.   
Next **T** lines will contain two integers **A** and **B** separated by a space.

###**OUTPUT FORMAT**   
Output should contain **T** lines, each conatining answer to Ramu's query explained above.

###**CONSTRAINTS:**   
Number of test cases **T**, **1 ≤ T ≤ 100**   
**1 ≤ A ≤ B ≤ 10<sup>15</sup>**

###**SAMPLE INPUT**   
2   
1 10   
40 50   

###**SAMPLE OUTPUT**   
3   
2

###**EXPLANATION**   
In the first test case **2**, **4** and **8** are the numbers between **1** and **10**.      
In the second test case **40** and **44** are the numbers between **40** and **50**.

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
    #include<iostream>
    #include<string>
    #define LL long long int
    #define rep(i,x,n) for(i=x;i<n;i++)
    using namespace std;

    LL kmh[25],p=0,dp[16][136];
    
    //returns string value of an integer
    string convert(LL n)
    {
        LL i,j,k;
        if(n==0)return "0";
        string str;
        for(i=n;i!=0;i/=10)
        {
            str=(char)(i%10+48)+str;
        }
        return str;
    }
    
    LL cal(LL n)
    {
        string str=convert(n);
        LL x=0,ans=0,i,j,k,bits,l=str.length();
        rep(i,0,l)
        {
            bits=l-i;
            rep(j,0,str[i]-48)
            {
                rep(k,0,p)
                {
                    if(kmh[k]-x-j>=0)ans+=dp[bits-1][kmh[k]-x-j];
                }
            }
            x+=(str[i]-48);
        }
        return ans;
    }
    
    int main()
    {
        LL i,j,k,n,t,a,b;
        
        //compute KMH numbers
        LL d[136]={0};
        for(i=2;i<136;i++)
        {
            if(!d[i])
            {
                for(j=i;j<136;j+=i)
                d[j]+=i;
            }
        }
        for(i=2;i<136;i++)if((d[i]&(d[i]-1))==0)kmh[p++]=i;

        //dp to compute number of integers of x bits with s sum as dp[x][s]
        rep(i,0,10)dp[1][i]=1;
        dp[0][0]=1;
        rep(i,2,16) //bits
        {
            rep(j,0,136)  //sum
            {
                rep(k,0,10) //setting MSB as k
                {
                    if(j-k>=0)
                    dp[i][j]+=dp[i-1][j-k];
                }
            }
        }
        
        cin>>t;
        while(t--)
        {
            cin>>a>>b;
            cout<<cal(b+1)-cal(a)<<endl;
        }
        return 0;
    }