You are on page 1of 1

Ma5termind and Subway are bored of their normal life.

They want to do something interesting so


that they can enjoy their last sem of college life.As usual Ma5termind comes up with a simple
and interesting game.

Ma5termind gives Subway a compressed string. A compressed String is composed of characters


and numbers.Every character in a compressed string contains a number. Ex a3b1c2 it
represents aaabcc. Other compressed string could be a22b2a1 , z5c2x36. Each number in the
compressed string indicates the number of times the corresponding character occurs in the
string. The final string is 1 indexed. Ma5termind wants Subway to sort the compressed string and
tell him the kth character in the sorted compressed string.Since subway got speed Ma5termind
asks him various such questions.

Help Subway in answering Ma5termind's question.

Input:

The first line contains the compressed string.This is followed by Q that indicates the number of
questions Ma5termind shoots on Subway.Follows Q lines each line contain an integer K.

Output:

For every question output the Kth character if it exists else print -1 .

Constraints:

2 <= Length of Compressed String <= 10^4

1<= Length of Final String <= 10^18

1<= Q <= 10^5

1<= K <= 10^18

Every character in the string is lowercase English letter.

Note:

The number for a character may contain leading zeroes.

You might also like