#Lutece0221. Counting Problem
Counting Problem
Migrated from Lutece 221 Counting Problem
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Snoworld just entered middle school. His math teacher enjoyed asking him strange questions. One of the questions is that how many numbers are there from to that doesn’t contain any . For example, if equals and equals , the answer would be and if equals and equals , the answer would be . Snoworld solved the question rather easily. So teacher complicated the question by asking it in an -base system and required the answer to presented in an -base system, so the and is -base number. For example, if equals and equals and equals , all the numbers are and the answer is .
Input
The first line of the input is an integer representing the number of cases, while is no more than .
The following lines each contain three integers and .
has no more than digits. .
Output
For each test case print one line with the answer presented in an -base system.
Samples
3
11 1 10
22 1 3
36 5 9
8
10
32
Resources
第四届北京邮电大学程序设计竞赛网络预赛