#d2955. 函数迭代求和
函数迭代求和
Iterated Function Summation
Problem Description
Define the function :
$$f(x)=\prod_{i=1}^{k}\bigl(x\bmod 10^i\bigr)\bmod (x+1),$$where is the number of digits of . For example, .
Define the function :
$$g(x,m)= \begin{cases} f\bigl(g(x,m-1)\bigr), & m>1,\\ f(x), & m=1. \end{cases}$$For example, .
You are given groups of . For each group, compute the value of .
Input Format
The first line contains an integer (), the number of test cases.
The next lines each contain two integers ().
Output Format
For each test case, output one integer on a single line.
Sample Input
2
3 4
4102 642
Sample Output
12
21262