P14044 [HackerEarth] You are given a number N. You can perform the following operation on it:-
普及
题目描述

You are given a number N. You can perform the following operation on it:-
Change any digit of N to a different digit. The cost of this operation is the absolute difference between the original and changed digits.
This operation can be performed any number of times. For example let N=12 , if we change the first digit to 2 and second digit to 1 the result becomes 21. The total cost involved in the conversion is |1-2| + |2-1|=2.
Your task is to determine how many distinct numbers which are divisible by 3 can be generated in this manner from the number N so that total cost of each conversion is less than equal to a given number C. You cannot change the first digit to 0.Here first digit implies the left most digit of an integer.

Input Format

The first line would consist of the number of test cases 'T'. This would be followed by 'T' lines consisting of two space separated integers N and C.

Constraints

1 ≤ T ≤ 100
1 ≤ N ≤ 10^50
1 ≤ C ≤ 2000

Output Format

For each test case output a single integer denoting the required value. Since the answer can be very large output the required value modulo 10^9+7.

Explanation For Sample Test

For the first case there are 8 such possible numbers:- 12,15,21,24,30,33,42 and 51.

SAMPLE INPUT
2
12 5
234 3

SAMPLE OUTPUT
8
24

输入格式

见题面

输出格式

见题面

样例输入
20 48282555556913268065647423480440698474562579250181 1204 42095149559704012963556108582908559151949010278604 355 48573645141334591952648603574329919337934895677394 718 67835255860706009513201454752591646482112225197873 1744 41081282474933507656375886070567320795646730445065 1397 6212890222197885124007201857772805464693763421190 646 69435916443870355726496567850372898462100598741386 1385 63132454522661392863533452652670782737367484185200 1341 52832164222146262673139384197184567046373145570680 855 8732503243711980368324025678541055421448404839341 925 32950384049977674846035529438093852619373360665735 44 37923810411002758618715227194340515467921597417811 566 24207428061051496436921875571701113320935904270621 1691 22417779748531112502829363719089743291919425172098 1915 21159028206497477458689085329013561972764174955076 1194 33746515529746032529838511851411847298733746553143 1511 90654254711870289894359593439188479643915372663657 1605 41731884469841142959414195884822123768648573856746 869 13943714680418794040312836752955402681950521798688 217 42262323967621242176572499711833785846716048761498 1580
样例输出
495790007 495543154 495790007 495790007 495790007 949579007 495790007 495790007 495790007 949579007 323816702 495790007 495790007 495790007 495790007 495790007 495790007 495790007 292693600 495790007