NUMTSN - 369 Numbers

no tags 

A number is said to be a 369 number if

  1. The count of 3s is equal to count of 6s and the count of 6s is equal to count of 9s.
  2. The count of 3s is at least 1.

For Example 12369, 383676989, 396 all are 369 numbers whereas 213, 342143, 111 are not.

Given A and B find how many 369 numbers are there in the interval [A, B]. Print the answer modulo 1000000007.

Input

The first line contains the number of test cases (T) followed by T lines each containing 2 integers A and B.

Output

For each test case output the number of 369 numbers between A and B inclusive.

Constraints

T<=100

1<=A<=B<=10^50

Sample Input

3

121 4325

432 4356

4234 4325667

Sample Output

60

58

207159

 


hide comments
ABHISHEK004: 2014-06-04 10:34:23

really an awesome problem!!!!!! made my day :)
Accepted after so many tle's and wrong answers...
thanks to the problem setter for such a problem.. learnt new things from this :D

yrocks: 2014-05-20 10:10:47

this problem cannot be solved in Python coz, range function cannot go till 10^50

(Tjandra Satria Gunawan)(曾毅昆): 2012-10-06 10:24:49

Silly mistake, I forgot about mod m, finally AC ;-) Nice problem...

devu: 2012-06-30 20:15:16

Finally Accepted!!
Learned a lot and thnxs a lot for the problem!!

Last edit: 2012-06-24 19:30:53
Saransh Bansal: 2012-06-30 20:15:16

Thanks a lot.. for your comments :)

Ehor Nechiporenko: 2012-06-30 20:15:16

Realy Awesome problem!!! :))

#vaidy_MIT#: 2012-06-30 20:15:16

awsme problem ...:)


Added by:Saransh Bansal
Date:2012-03-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64