#K50202. K-th Occurrence of a Character
K-th Occurrence of a Character
K-th Occurrence of a Character
You are given a string \(S\) consisting of lowercase English letters and \(Q\) queries. Each query specifies a character \(c\) and an integer \(k\). For every query, you must determine the position (1-indexed) of the \(k\)-th occurrence of the character \(c\) in \(S\). If \(c\) occurs fewer than \(k\) times, output \(-1\).
Input Format: The first line contains the string \(S\). The second line contains an integer \(Q\) representing the number of queries. Each of the following \(Q\) lines contains a character and an integer separated by spaces.
Output Format: For each query, output the answer on a new line.
inputFormat
The input is read from standard input (stdin) and has the following format:
S Q c1 k1 c2 k2 ... cQ kQ
where:
S
is a non-empty string of lowercase English letters.Q
is the number of queries.- Each query consists of a character
c
and an integerk
.
outputFormat
For each query, output a single integer on a new line. The integer is the 1-indexed position of the \(k\)-th occurrence of the given character \(c\) in \(S\) or \(-1\) if it does not exist.
## sampleababab
3
a 1
b 2
c 1
1
4
-1
</p>