#K55177. K-system to Decimal Conversion

    ID: 29918 Type: Default 1000ms 256MiB

K-system to Decimal Conversion

K-system to Decimal Conversion

This problem requires you to convert a number from a K-based numeral system to its equivalent in decimal (base 10). In a K-system number, each digit belongs to a base \(k\) where \(2 \le k \le 10\). The conversion should be done using the formula:

\[ \text{value} = \sum_{i=0}^{n-1} d_i \times k^{n-1-i} \]

where \(d_i\) represents the \(i\)-th digit of the number. You are given several test cases; for each test case, compute and output the corresponding decimal number.

inputFormat

The first line of input contains an integer \(T\) denoting the number of test cases. Each of the following \(T\) lines represents a test case. Each test case contains a sequence of space-separated integers: the first integer is \(k\) (the base) and the rest of the integers are the digits of the number in the K-system. For example:

3 1 2 1

Here, \(k=3\) and the K-system number is [1, 2, 1].

outputFormat

For each test case, output a single line containing the decimal (base 10) equivalent of the provided K-system number.

## sample
1
3 1 2 1
16

</p>