Big Integer
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

For little pupils, a very large number usually means an integer with many many digits. Let's define a class of big integers which consists only of the digit one . The first few integers in this class are . Denote  as the -th smallest integer in this class. To make it even larger, we consider integers in the form of . Now, given a prime number , how many pairs  are there such that .

输入描述:

The input contains multiple cases. The first line of the input contains a single integer , the number of cases.
For each case, the input consists of a single line, which contains 3 positive integers .

输出描述:

Print the answer, a single integer, in one separate line for each case.
示例1

输入

复制
2
11 8 1
7 6 2

输出

复制
4
2