PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT00000052. Tín hiệu nén (Compressed Signal)

Bài tập này chưa được xếp vào lộ trình.

Tín hiệu nén (Compressed Signal)

Compressed Signal

Version: Phuoc Hung OJ Extended

Problem Statement

A device stores an original signal consisting only of lowercase English letters from a to z. To save space, the signal is represented as a sequence of consecutive groups. Each group contains a letter cc repeated kk times and is encoded as the positive decimal integer kk immediately followed by cc.

Concatenating all encoded groups in their original order produces the compressed string SS. Repetition counts have no leading zeros. Adjacent groups may contain the same letter; they are not required to be merged.

For example, S=S= 3a2b4a represents aaabbaaaa: three a letters, then two b letters, then four a letters. Positions in the decoded signal are numbered from 11 through its total length.

You are given QQ queries. Each query specifies a position PP in the original signal. Determine the letter at exactly position PP, without having to output the entire decoded signal.

Input

  • The first line contains the compressed string SS with no spaces. It consists of one or more valid groups, each encoded as a positive repetition count followed by a lowercase English letter.
  • The second line contains the positive integer QQ, the number of queries.
  • Each of the next QQ lines contains a positive integer PiP_i, the queried position in the decoded signal. All queried positions are valid.

Output

Print exactly QQ lines in query order. Line ii contains one lowercase English letter: the letter at position PiP_i of the decoded signal.

Subtasks

The following general constraints apply to all subtasks: 1≤∣S∣≤2⋅1051\le |S|\le 2\cdot 10^5; 1≤Q≤2⋅1051\le Q\le 2\cdot 10^5; each group count is in [1,1012][1,10^{12}]; the decoded length is at most 101810^{18}; 1≤Pi≤1\le P_i\le the decoded length.

  • Subtask 1 (30%): The decoded length is at most 10510^5.
  • Subtask 2 (30%): Every group count is at most 99.
  • Subtask 3 (40%): No additional restrictions beyond the general constraints.

Examples

Example 1

Input

3a2b4a
6
1
3
4
5
6
9

Output

a
a
b
b
a
a

Explanation

The groups in 3a2b4a occupy the following positions: 11 through 33 contain a, 44 through 55 contain b, and 66 through 99 contain a. The queried positions 1,3,4,5,6,91,3,4,5,6,9 therefore produce a, a, b, b, a, a, in that order.

Example 2

Input

12z1a
3
1
12
13

Output

z
z
a

Explanation

Group 12z occupies positions 11 through 1212, all containing z. Group 1a occupies position 1313. Therefore positions 11, 1212, and 1313 contain z, z, and a, respectively.

Example 3

Input

1a1a1b
3
1
2
3

Output

a
a
b

Explanation

The three groups 1a, 1a, and 1b have lengths 1,1,11,1,1. The first two groups are valid even though they share the same letter, and the decoded signal is aab. Positions 11, 22, and 33 therefore contain a, a, and b.