Cool numbers

2.5

2 votes
Implementation, Recruit, approved, Easy-Medium, Ready, Mathematics, Approved
Problem

Today Oz is busy with cool numbers. Cool numbers are positive integers whose decimal representation contains only the cool digits 2 and 5. For example, numbers 25, 522, 2 are cool and 7, 15, 265 are not.
Let f(k) be the smallest cool number greater than or equals k. Oz is interested what is the value of the following expression for a given pair (l,r) :
enter image description here

Input :
The first line of input contains an integer T - number of test cases. Each test case consist of two integers l and r.

Output :
For each test case output required answer.

Constraint :
1 ≤ T ≤ 50
1 ≤ l ≤ r ≤ 109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first sample:
f(3)+f(4)+f(5)+f(6)+f(7)=5+5+5+22+22=59

Editor Image

?