Master Zhu and Palindromes

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

문제

Master Zhu has a string S\[1,,n]S \[1, \ldots, n]. This string can contain only the first five lowercase English letters. Another peculiar property of SS is that the length of each palindrome substring in SS is less than 2020.

For a palindrome string P\[1,,k]P \[1, \ldots, k], its tail is the string P\[k/2+1,,k]P \[\lfloor k / 2 \rfloor + 1, \ldots, k]. For example, the tail of the string "aba" is "ba", and the tail of the string "caac" is "ac".

Given LL, RR, and a string TT, Master Zhu wants you to find the number of different palindrome substrings in S\[L,,R]S \[L, \ldots, R] such that TT is a prefix of their tails. Here, two substrings are considered different if their starting or ending positions in SS differ.

입력

The first line of input contains one integer CC, the number of test cases (1C501 \le C \le 50).

The first line of each test case contains a string SS consisting only of the first five lowercase English letters (1S1051 \le |S| \le 10^5, the length of each palindrome substring in SS is less than 2020).

The second line contains one integer qq, the number of queries (1q1051 \le q \le 10^5). Each of the next qq lines contains two integers LL and RR and a string TT consisting only of the first five lowercase English letters (1LRS1 \le L \le R \le |S|, 1T101 \le |T| \le 10).

출력

For each query, print a single line with a single integer: the number of different palindrome substrings in S\[L,,R]S \[L, \ldots, R] such that TT is a prefix of their tails.