F

Krypton Number System

Input: Standard Input

Output: Standard Output

 

All of you must have heard the name of the planet Krypton. If you can’t remember the planet, don’t worry. Planet Krypton is the origin of Superman, that means the mother planet where Superman was born. Superman was sent to earth by his parents when the planet was about to explode. Legends say that only few people of the planet survived from that explosion.

 

The inhabitants of the planet is called ‘Kryptonians’. Kryptonians, though otherwise completely human, were superior both intellectually and physically to natives of Earth. One of the most common differences is their number system. The number system is denoted below

 

1)      The base of the number system is unknown, but legends say that the base lies between 2 and 6.

2)      Kryptinians don’t use a number where two adjacent digits are same. They simply ignore these numbers. So, 112 is not a valid number in Krypton.

3)      Numbers should not contain leading zeroes. So, 012 is not a valid number.

4)      For each number, there is a score. The score can be found by summing up the squares of differences of adjacent numbers. For example 1241 has the score of

(1-2)2 + (2-4)2 + (4-1)2 = 1 + 4 + 9 = 14.

5)      All the numbers they use are integers.

Now you are planning to research on their number system. So, you assume a base and a score. You have to find, how many numbers can make the score in that base.

 

 

Input

The first line of the input will contain an integer T (<= 200), denoting the number of cases. Then  T cases will follow.

 

Each case contains two integers denoting base (2 <= base <= 6) and score (1 <= score <= 109). Both the integers will be given in decimal base.

 

 


Output

For each case print the case number and the result modulo 232. Check the samples for details. Both the case number and result should be reported in decimal base

 

Sample Input                              Output for Sample Input

2

6 1

5 5

Case 1: 9
Case 2: 80

 

Problem setter: Jane Alam Jan, Special Thanks: Manzurur Rahman Khan