An N -based number is beautiful if all of the digits from 0 to N − 1 are used in that number and the difference between any two adjacent digits is exactly 1 (one). For example, 9876543210 is a 10-based beautiful number. You have to calculate the number beautiful numbers that has got atmost M digits... Note: No leading zero is allowed in a beautiful number.
The first line of input is an integer T (T < 100) that indicates the number of test cases. Each case starts with a line containing two integers N and M (2 ≤ N ≤ 10 & 0 ≤ M ≤ 100).
For each case, output the number of beautiful N -based numbers, which are using less than or equal to M digits in a single line. You have to give your output modulo 1000000007.
範例輸入 1
3 2 4 3 7 10 10
範例輸出 1
3 31 1
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.