Happy Range X78898


Statement
 

pdf   zip

Welcome to the world of happy numbers. In this world, only digits 44 and 77 are happy while the rest are unhappy, so happy numbers are those composed of 44s and 77s, e.g. 123456123456 and 47494749 are unhappy but 774774 and 47474747 are happy numbers.

Given two numbers AA and BB, print the amount of happy numbers in the range [A,B][A, B] such that 0A<B1090 \leq A < B \leq 10^9.

Input

The input starts with the number of test cases T1000T \leq 1000. For each test case, there are two integers AA and BB that corresponds to range where we have to look for happy numbers.

Output

For each test case, output the total number of happy numbers in the range [A,B][A,B].

In the first example, in [1,10][1,10] only 44 and 77 are happy so the answer is 22.

In the second example, in [44,450][44,450], the happy numbers are 4444, 4747, 7474, 7777, 444444 and 447447 so the answer is 66.

Public test cases
  • Input

    2
    1 10
    44 450
    

    Output

    2
    6
    
  • Information
    Author
    Javier Segovia
    Language
    English
    Official solutions
    C++
    User solutions
    C++