logo AlgoBeat OnlineJudge
登录 注册

#209486. [ICPC 2018 Qingdao R] Function and Function

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

If we define , do you know what function means?

Actually, calculates the total number of enclosed areas produced by each digit in . The following table shows the number of enclosed areas produced by each digit:

For example, , and .

We now define a recursive function by the following equations:

For example, , and .

Given two integers and , please calculate the value of .

输入格式

There are multiple test cases. The first line of the input contains an integer (about ), indicating the number of test cases. For each test case:

The first and only line contains two integers and (). 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 .

样例

样例输入 1

6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0

样例输出 1

5
18
2
0
0
1000000000

数据范围与提示