Under construction

Still being built. Things may change

The Lucky Numbers

Time limit1sMemory limit128 MB

Summary
Count lucky numbers (digits 4 and 7 only) in [A,B], plus lucky numbers outside the range whose digit-reversal lands inside it, for B up to 10^47.
Level

Medium6 of 10

Topics
Combinatorics, Math, Brute force
Solved
No attempts yet

Problem

John and Brus are freshmen at primary school. Their first homework is to learn some integers, and to impress their teacher they decide to memorize every lucky number in the range from AA to BB, inclusive.

As you may recall from last year's contest, the lucky digits are 44 and 77; every other digit is not lucky. A lucky number is a number whose decimal representation contains only lucky digits.

After memorizing every lucky number in [A,B][A, B], the two still have free time, so they additionally memorize each lucky number NN that lies outside [A,B][A, B] but whose reversed number falls inside [A,B][A, B]. The reversed number of NN is NN written in decimal with the order of its digits reversed. For example, the reversed number of 447447 is 744744, and the reversed number of 774474444774474444 is 444474477444474477.

Given the integers AA and BB, find the total number of lucky numbers that John and Brus memorize.

Input

The first line contains a single integer TT, the number of test cases. Each test case is a single line containing two integers AA and BB separated by a single space.

Output

For each test case, print on its own line the total number of lucky numbers that John and Brus memorize.

Constraints

  • 1≤T≤741 \le T \le 74
  • 1≤A≤B≤10471 \le A \le B \le 10^{47}

Examples1

  1. Example 1

    Input
    2
    1 100
    44 47
    
    Expected output
    6
    3