Another Substring Query Problem

아직 제출이 없습니다시간 제한6초메모리 제한1024 MB

문제

You are given a string ss and several queries.

Each query consists of a string tt and an integer kk. For each query, determine the kkth position in ss where a substring matching tt starts. If tt occurs fewer than kk times in ss, print −1.

입력

The first line of input contains a single string ss (1s2 1051 \le |s| \le 2 \cdot 10^5), which is the queriable string. It will consist only of lower-case letters.

The next line of input contains a single integer qq (1q21051 \le q \le 2 \cdot 10^5), which is the number of queries that follow.

Each of the next qq lines contains a string tt (1t1 \le |t|) and an integer kk (1ks1 \le k \le |s|). This represents a query for the kkth occurrence of tt in ss. The string tt will consist only of lower-case letters. The sum of all t|t|’s will be 2105\le 2 \cdot 10^5.

출력

Output a single integer, which is the position of the start of the kkth occurrence of tt in ss, or −1 if tt occurs fewer than kk times in ss. The first character in ss is at position 1.