1034: Number system 1
[Creator : ]
Description
Given a number A which is an X base number system value, please convert it to decimal (based on 10). For each digit K in A, we use (K) to represent it.
For example, given A = (2)(50)(30) based on 60 number system, then its decimal value is 2*602 + 50*601+30*600 which is 7200 + 3000 + 30 = 10230
For example, given A = (2)(50)(30) based on 60 number system, then its decimal value is 2*602 + 50*601+30*600 which is 7200 + 3000 + 30 = 10230
Input
The first line contains an integer T which is the number of cases.
In the following T line, there are two fields in each line, the first field is the number and the second field is the base.
(you can assume all are positive integers and no spaces in the number for input)
In the following T line, there are two fields in each line, the first field is the number and the second field is the base.
(you can assume all are positive integers and no spaces in the number for input)
Output
For each case, output the decimal value (the value is less than 1015 )
Sample Input Copy
3
(2)(50)(30) 60
(1)(0)(1) 2
(1)(0)(15) 16
Sample Output Copy
10230
5
271