Time Limit: 1000ms
Memory Limit: 65536kb
DescriptionA number is called 'ugly number' if and only if it is composed of digit 2 or 5 or 8. So the first ten 'ugly number' are: 2 5 8 22 25 28 52 55 58 82.
Now, we define two functions:
next(x) : the minimum 'ugly number ' greater or equal to x.
pre(x) : the maximum 'ugly number ' smaller or equal to x.
For example, next(3)=5, pre(24)=22.
Given an interval [S, D] (S<=D), can you compute the value of TT, defined as:
InputThe input consists of multiple test cases.
The first line, an integer T (1<=T<=100), indicates the number of test cases. Each test case has only one line, containing two numbers S and D, in which:
OutputOutput the answer of each case.
1 2 4