CONFUSING TREE AGAIN

3.3

3 votes
Medium
Problem

Mr. Robot has a string S (made of lowercase letters), he takes up that string and start dividing it in two half till string of length one is left, for example, as shown in the image below
.enter image description here

He takes string abcdefghij and divides in two half as abcde and fghij. Now string abcde is divided into further two half as abc and de and similarly the string fghij is divided into fgh and ij. This is done till the string of length one as shown. Now Mr. Robot takes every divided part as a node i.e. abcdefghij as one node, abcde as another node and fghij as another node. Similarly nodes at last level have values a, b, f and g. Now he considers every nodes of the last level in ordered way from 1 to number of nodes on last level, like in this case the the ordered way is 1, 2 ,3 ,4. where 1st indexed node on last level has character a, 2nd indexed node on last level has character b, 3rd indexed on last level has character f and 4th indexed node on last level has character g as can be seen in the image, the encircled part is the last level of the tree so formed.
Mr. Robot is smart so he keeps every important data on last level. So can you grab his last level data and be smarter than him.
Given the string S and q number of queries for the string. In each query an index (1-based) is given, you need to print the data at that index of the last level when the indexing is followed as explained above. See the sample explanation for more clarifications.
INPUT
The first line contains the no. of test cases t and each test case contains string S and no. of queries q. Next q lines contains indexes idx.
OUTPUT
For each test case print case no as "Case i:" (without quotes) and next q lines contains the data at the index idx of the last level, when followed in ordered way (1,2,3 ... ... , n) , where n is nth node or last node on last level.
CONSTRAINTS
1<=t<=6
1<=|S|<=1024
1<=q<=idx<=Index of the last node on last level.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first case, the tree is as shown above. And here no. of queries is 4, and first query is for index 1 which is first node of the last level i.e. "a", and second query is for index 2 which is second node of the last level i.e. "b" and third query is for index 3 which is third node of the last level i.e. "f" and fourth query is for index 4 which is the last node or fourth node of last level i.e. "g".
Hence the output is a , b , f , g.
Similarly for other two cases.

Editor Image

?