#B3869. Base Conversion Challenge

    ID: 11526 Type: Default 1000ms 256MiB

Base Conversion Challenge

Base Conversion Challenge

In this problem, you are given several numbers in various bases. A number in base \(N\) is expressed in a numeral system where each digit represents a power of \(N\). For bases greater than 10, the digits from 10 to 15 (if applicable) are represented by the uppercase letters A, B, C, D, E, and F respectively. Your task is to convert each given number into its decimal (base 10) equivalent.

The conversion from a base \(B\) number \(s\) to decimal is computed as follows:

[ \text{value} = \sum_{i=0}^{L-1} d_i \times B^{(L-1-i)} ]

where \(L\) is the length of the number and \(d_i\) is the integer corresponding to the \(i^{th}\) digit (with A representing 10, B representing 11, etc.).

inputFormat

The first line contains an integer \(T\) representing the number of test cases. Each of the next \(T\) lines contains a test case with an integer \(B\) (the base of the number) and a string \(s\) representing the number in that base, separated by a space.

outputFormat

For each test case, output a single line containing the decimal (base 10) conversion of the given number.

sample

3
2 1010
16 1A
8 17
10

26 15

</p>