#CT00040. Truy vấn giải nén (Decompression Queries)

    ID: 230 Loại: Thông thường 2000ms 256MiB Tried: 8 Đã chấp nhận: 4 Độ khó: 1 Đăng bởi: Nhãn>String AlgorithmsString processing basicsSorting and SearchingBinary searchFundamentalsInteger overflow

Truy vấn giải nén (Decompression Queries)

Decompression Queries

Version: Phuoc Hung OJ Extended

Problem Statement

An original string was run-length encoded: every maximal consecutive run of equal uppercase letters is represented by its letter followed by a positive integer count. The encoded string EE is therefore a sequence of letter-count pairs, and a count may contain multiple digits.

The original string may be too long to materialize in memory.

There are QQ queries. Query ii gives a 1-based position pip_i in the original string. Determine the character at that position for every query, then concatenate the answers in query order into a string of length QQ.

Input

  • Line 1 contains a valid encoded string EE.
  • Line 2 contains the positive integer QQ.
  • Line 3 contains QQ positive integers p1,p2,…,pQp_1,p_2,\ldots,p_Q. Every pip_i is at most the decompressed length.

Output

Print a string of exactly QQ characters. Its ii-th character is the character at position pip_i in the original string.

Subtasks

  • Subtask 1 (30 points): the decompressed length is at most 10510^5 and Q≤103Q\le10^3.
  • Subtask 2 (30 points): Q≤103Q\le10^3.
  • Subtask 3 (40 points): no additional restriction.
  • In every subtask: ∣E∣≤106|E|\le10^6, Q≤2⋅105Q\le2\cdot10^5, and the decompressed length is at most 101810^{18}.

Examples

Input

A3B1C4D3A1
5
1 4 8 9 12

Output

ABCDA

Explanation

The encoded string represents AAABCCCCDDDA. Positions 1,4,8,9,121,4,8,9,12 lie in the runs for A, B, C, D, and A respectively, so the answer is ABCDA.