#Q170. 「一本通 5.3 练习 3」恨 7 不成妻
「一本通 5.3 练习 3」恨 7 不成妻
Description
Original source: HDU 4507
Single!
Still single!
Brother Ji is still single!
DS-level coder Brother Ji is still single!
Thus, he despises Valentine's Day the most, whether it's or , he hates them all!
Brother Ji observed the numbers and and found:
$$\begin{align} 2+1+4&=7\\ 7+7&=7\times 2\\ 77&=7\times 11 \end{align} $$Eventually, he realized that all of this boils down to their connection with the number ! Therefore, he now even hates all numbers related to !
What kind of numbers are related to ? If an integer meets any of the following three conditions, we say it is related to :
- One of its digits is ;
- The sum of its digits is a multiple of ;
- The integer itself is a multiple of .
Now the question arises: Brother Ji wants to know the sum of the squares of numbers within a certain interval that are unrelated to .
Input Format
The first line of input data is the number of test cases , followed by lines representing test cases.
Each case consists of two positive integers and on a single line.
Output Format
For each test case, compute the sum of the squares of numbers in that are unrelated to , and output the result modulo .
Sample 1
3
1 9
10 11
17 17
236
221
0
Data Range and Hints
For all data, .