#abc242d. D - ABC Transform

D - ABC Transform

Score : 400400 points

问题描述

你将获得一个由 A, B, C 组成的字符串 SS

S(0):=SS^{(0)}:=S。对于 i=1,2,3,i=1,2,3,\ldots,通过如下方式同时替换 S(i1)S^{(i-1)} 的字符来定义 S(i)S^{(i)}ABCBCACAB

解答 QQ 个查询。第 ii 个查询如下:

  • 打印 S(ti)S^{(t_i)} 开头的第 kik_i 个字符。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS consisting of A, B, C.

Let S(0):=SS^{(0)}:=S. For i=1,2,3,i=1,2,3,\ldots, let S(i)S^{(i)} be the result of simultaneously replacing the characters of S(i1)S^{(i-1)} as follows: ABC, BCA, CAB.

Answer QQ queries. The ii-th query is as follows.

  • Print the kik_i-th character from the beginning of S(ti)S^{(t_i)}.

Constraints

  • SS is a string of length between 11 and 10510^5 (inclusive) consisting of A, B, C.
  • 1Q1051 \leq Q \leq 10^5
  • 0ti10180 \leq t_i \leq 10^{18}
  • 1kimin(1018,1 \leq k_i \leq \min(10^{18}, the length of S(ti))S^{(t_i)})
  • Q,ti,kiQ, t_i, k_i are integers.

Input

Input is given from Standard Input in the following format:

SS

QQ

t1t_1 k1k_1

t2t_2 k2k_2

\hspace{0.4cm}\vdots

tQt_Q kQk_Q

Output

Process the QQ queries in ascending order of index, that is, in the given order. Each answer should be followed by a newline.

Sample Input 1

ABC
4
0 1
1 1
1 3
1 6

Sample Output 1

A
B
C
B

We have S(0)=S^{(0)}=ABC, S(1)=S^{(1)}=BCCAAB.

Thus, the answers to the queries are A, B, C, B in the given order.

Sample Input 2

CBBAACCCCC
5
57530144230160008 659279164847814847
29622990657296329 861239705300265164
509705228051901259 994708708957785197
176678501072691541 655134104344481648
827291290937314275 407121144297426665

Sample Output 2

A
A
C
A
A

update @ 2024/3/10 10:25:24