Little Elephant and Product

All submissions for this problem are available.
A Little Elephant from the Zoo of Lviv likes lucky numbers very much. Everybody knows that the lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let F_{4}(X) be the number of digits 4 in the decimal representation of X, and F_{7}(X) be the number of digits 7 in the decimal representation of X. For example, F_{4}(456) = 1, F_{4}(444) = 3, F_{7}(1) = 0, F_{7}(747) = 2. The Little Elephant wants to know the largest product F_{4}(X) ∙ F_{7}(X), where L ≤ X ≤ R. In other words he wants to know the value
max{F_{4}(X) ∙ F_{7}(X) : L ≤ X ≤ R}.
Input
The first line of the input file contains an integer T, the number of test cases. T test cases follow. The only line of each test case contains two integers L and R separated by exactly one space.
Output
For each test case output a single line containing the answer for the corresponding test case.
Constraints
1 ≤ T ≤ 1000
1 ≤ L ≤ R ≤ 10^{18}
Example
Input: 3 1 10 1 100 47 74 Output: 0 1 1
Explanation
In both second and third test cases the maximal product is achieved at the numbers 47 and 74.
Author:  witua 
Tester:  anton_lunyov 
Editorial  http://discuss.codechef.com/problems/LUCKY8 
Tags  adhoc, easy, june12, witua 
Date Added:  3022012 
Time Limit:  0.388889 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 