GONE - G-One Numbers

The War of Evil vs Good continues and Ra-One and G-One continue to be on respective sides.

After saving all the cities with Ra-One Numbers G-One realised that some cities whose population is a "G-One Number" can be easy target for Ra-One.

A G-One number is a number sum of whose digits is a prime number

For example 12 .. sum = 1+2 = 3 ... 3 is a prime number.

G-One wants to find out all the populations which can be g-One numbers....

Can You help him.?

You will be given the range of population and you have to tell him how many in this range are G-One Numbers.

Input

first line has number 'c' indicating the number of ranges.

'c' lines follow and contain two numbers ... 'f' and 't' inclusive.

Output

Print a single line per case giving the number of populations which are G-One numbers.

Example

Input:
3
10 19
1 9
20 29

Output: 4
4
5

Note: c will be less than 100
t and f will be less than 10^8 inclusive


Added by:Devil D
Date:2012-02-24
Time limit:1s
Source limit:30000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own

hide comments
2019-09-08 16:02:19
4th digit dp AC in one go
2018-12-30 12:57:10 hacker_sk
AC in two GO :P
2018-01-24 17:52:18
AC in one GO;)
2017-09-07 15:59:56
AC in one GO;)
2016-04-08 22:48:01 Vivek Mangal
very nice problem
2015-08-22 22:52:22 Medo
One of the best problems I solved.
2015-05-31 06:42:34 parijat bhatt
Both numbers are inclusive.
2014-10-21 08:48:59 Gaurav Kumar Verma
worst case Test Case
1
1 100000000
24786388
2014-09-13 14:15:19 lifeofpie
@All can any one tell me why i m getting runtime error SIGKILL after runtime(2) ...
Thanks
2014-05-26 14:08:47 super human
nice one!!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.