Given the number of digits and a base, give the count of all the special numbers present in the range from zero to maximum for that combination of number of digits and base.

Special number is defined as a number whose sum of digits in left half is equal to the sum of digits in its right half. For example, for base 10 and number of digits 4, total possible numbers will be 0000 to 9999, and in this range, 0642 is one special number as 0 + 6 = 4 + 2.

Assumption:There are no test cases with odd number of digits.

**Input:**

First line contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an integer N, denoting the number of digits in the number. Second line of each test case contains an integer B, denoting the base.

**Output:**

For each test case print in a new line the count of all special numbers.

**Constraints:**

1 <= T <= 70

1 <= N <= 6

1 <= B <= 10

**Example:**

**Input:**

2

4

2

2

10

**Output:**

6

10

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

mantan_g | 267 |

tushki | 198 |

aksht7 | 182 |

ayush1101 | 128 |

namansharmacse17 | 110 |

ARUN_PUNDIR | 730 |

manishgupta8497 | 627 |

AMAN__JAIN | 625 |

Abhimanyu_kumar | 562 |

AJ786 | 541 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4584 |

Login to report an issue on this page.