Under construction

Still being built. Things may change

Ten Ranges

Time limit2sMemory limit512 MB

Summary
Count the integers in each range [l, r] (r up to 10^18) that have no prime as a decimal subsequence, for up to 10 queries.
Level

Medium7 of 10

Topics
Dynamic programming, String matching, Number theory
Solved
No attempts yet

Problem

An integer xx is a decimal subsequence of an integer yy if the decimal representation of xx can be obtained from that of yy by erasing some digits. Erasing no digits is allowed, but not all of them.

An integer xx is prime if x≥2x \ge 2 and its only positive divisors are 1 and xx.

An integer xx is secondary if no integer yy that is prime is a decimal subsequence of xx. For example, 168 is secondary because none of 1, 6, 8, 16, 18, 68, and 168 is prime, while 169 is not secondary because 19 is prime.

Find the number of secondary integers in each range [l;r][l; r].

Input

The first line contains a single integer nn (1≤n≤101 \le n \le 10), the number of ranges.

Each of the following nn lines contains two integers ll and rr (1≤l≤r≤10181 \le l \le r \le 10^{18}), the boundaries of one range.

Output

Print the number of secondary integers in each given range, in the order of input.

Hint

In the example test case, the secondary integers in [8;16][8; 16] are 8, 9, 10, 14, and 16. The secondary integers in [157;174][157; 174] are 160, 164, 166, and 168.

Examples1

  1. Example 1

    Input
    3
    8 16
    157 174
    42 239
    
    Expected output
    5
    4
    36