You are given a string with length . Furthermore, you are given queries. Each query will be of the following format:
- , asking for the number of substrings in string between position and that are palindromic.
A string is a palindrome if it meets the following condition: .
Input Specification
The first line contains a string , with a length . The string will only consist of lowercase letters.
The second line of input contains an integer .
The next lines of input will contain 2 space separated integers, and .
Output Specification
You are to output integers, the solutions to the queries.
Subtasks
Subtask 1 [30%]
Subtask 2 [70%]
No further constraints.
Sample Input
aaaaabbbaa
5
7 9
4 6
6 7
1 8
1 10
Sample Output
4
4
3
21
26
Comments