Operation Zero Tolerance

0

0 votes
Easy
Problem

Cerebro was a machine designed by Professor Charles Xavier to locate mutants with the X-Gene, and it was located in Xavier’s mansion on the second sub-basement under heavy security.

Bastion assembled the international anti-mutant strike force and launched Operation: Zero Tolerance, in order to confiscate Cerebro. He has managed to reach the basement, but has to enter a K digit passcode to proceed further. However, the passcode isn’t so simple. The ith digit of the passcode is the value of the Kith digit of the Xavier constant. The Xavier constant is defined by concatenating representations of successive integers.

Xavier constant = 123456789101112131415161718.....

Bastion was able to fnd the answer for very small values of Ki, but needs your help to calculate the answer for extremely large values of Ki. You will be given K queries in the form of space separated integers. For each query you have to fnd the value of the Kith digit of the Xavier constant and output the K- digit passcode in a single line.

INPUT
First line of input contains an positive integer T – denoting the number of test cases. The fIrst line of each test case contains an integer K- denoting the number of queries. The second line of test case contains K space-separated integers where Ki denotes the digit whose value in the Xavier constant is to be calculated.

CONSTRAINTS
1 <= T <= 100
1 <= K <= 15
Subtask 1: 20 points
  1 <= Ki <= 106
Subtask 2: 80 points
  1 <= Ki <= 1015

OUTPUT
For each test case, in a single line print the correct K-digit passcode (without spaces).

Sample Input
2
4
2 5 12 14
3
3 15 20
Sample Output
2511
321
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In Test Case 1, the value of 2nd, 5th , 12th and 14th digit in the Xavier Constant is 2, 5, 1 and 1 respectively, hence the passcode is 2511.

123456789101112131415161718.....

In Test Case 2, the value of 3rd , 15th and 20th digit in the Xavier Constant is 3, 2 and 1 respectively, hence the passcode is 321.

123456789101112131415161718.....

Editor Image

?