The sum squared digits function SSD(b,n) is the sum of the squares of the digits of that representation.
SSD(b,n)=a02+a12+a22+⋯
Write a program that computes the sum squared digits function of a given positive integer.
Input
The first line contains one decimal integer P, the number of data sets that follow. (1≤P≤10000)
Each of the next P lines holds one data set. The data sets are independent and are all processed the same way.
A line contains the data set number K, the base b (3≤b≤16), and the positive integer n whose sum squared digits value in base b is to be computed, separated by spaces. All three values are decimal integers, and n fits in a 32 bit unsigned integer.
Output
Print one line for each data set.
The line contains the data set number K, a single space, and the value of SSD(b,n) as a decimal integer.