NUMTSN - 369 Numbers

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

 


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

hide comments
2017-05-22 06:22:56
finally AC,silly mistake
2016-06-23 22:49:15
1 -> 10^50 : 129112454
2016-01-24 18:38:34 kejriwal
Awesome Problem :')
2016-01-21 22:03:24
still cant figure out why i am getting WA...-_-
2016-01-18 18:18:30 ashish kumar
finally accepted
2015-11-12 09:09:47 Vu Duy Truc
Please give me some testcase ???

I have test this case:
1 -> 10^50 ====> output = 129112454 OR 92044422


Am I wrong?

Last edit: 2015-11-13 03:01:25
2015-08-08 13:39:34 elita lobo
@Saransh Bansal, Can you please check my code and tell me why I am getting wa? id- 14848296
2015-06-05 07:50:39 mayank
Mazza Aa Gaya! :)
2014-09-02 18:54:42 Durga Tiwari
awesome problem :) hats off to setter !!
2014-06-11 22:42:54 David
I'm using a dp table dp[51][18][18][18][2] and getting TLE. Is the dimension of the table correct? or am i doing this completely wrong?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.