The Lucky Numbers

Time limit1sMemory limit128 MB

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 $A$ to $B$, inclusive.

As you may recall from last year's contest, the lucky digits are $4$ and $7$; 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]$, the two still have free time, so they additionally memorize each lucky number $N$ that lies outside $[A, B]$ but whose reversed number falls inside $[A, B]$. The reversed number of $N$ is $N$ written in decimal with the order of its digits reversed. For example, the reversed number of $447$ is $744$, and the reversed number of $774474444$ is $444474477$.

Given the integers $A$ and $B$, find the total number of lucky numbers that John and Brus memorize.

Input

The first line contains a single integer $T$, the number of test cases. Each test case is a single line containing two integers $A$ and $B$ 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 \le T \le 74$
  • $1 \le A \le B \le 10^{47}$