题目描述
If we define f(0)=1,f(1)=0,f(4)=1,f(8)=2,f(16)=1,…, do you know what function f means?
Actually, f(x) calculates the total number of enclosed areas produced by each digit in x. The following table shows the number of enclosed areas produced by each digit:

For example, f(1234)=0+0+0+1=1, and f(5678)=0+1+0+2=3.
We now define a recursive function g by the following equations:
{g0(x)=xgk(x)=f(gk−1(x))if k≥1For example, g2(1234)=f(f(1234))=f(1)=0, and g2(5678)=f(f(5678))=f(3)=0.
Given two integers x and k, please calculate the value of gk(x).
输入格式
There are multiple test cases. The first line of the input contains an integer T (about 105), indicating the number of test cases. For each test case:
The first and only line contains two integers x and k (0≤x,k≤109). Positive integers are given without leading zeros, and zero is given with exactly one `0'.
输出格式
For each test case output one line containing one integer, indicating the value of gk(x).
题目大意
题目描述
如果我们定义 f(0)=1,f(1)=0,f(4)=1,f(8)=2,f(16)=1 …… 你知道函数 f 意味着什么吗?
其实,f(x) 计算的是 x 中每个数字所产生的封闭区域的总数。下表显示了每个数字产生的封闭区域数:

例如,f(1234)=0+0+0+1=1,f(5678)=0+1+0+2=3。
现在,我们用以下等式定义递归函数 g:
{g0(x)=xgk(x)=f(gk−1(x))if k≥1例如,g2(1234)=f(f(1234))=f(1)=0,g2(5678)=f(f(5678))=f(3)=0。
给定两个整数 x 和 k,请计算 gk(x) 的值。
输入格式
有多个测试用例。输入的第一行包含一个整数 T(大约 105),表示测试用例的数量。
之后的每行包含两个整数 x 和 k(0≤x,k≤109)。正整数不带前导零,零则正好是一个 "0"。
输出格式
对每个测试用例输出一行,其中包含一个整数,表示 gk(x) 的值。
提示
