Palindromes and Queries 2

Given a string and queries, each query asks how many palindromic substrings start at a given index with length at least a given value.

Hard8StringString matchingMathBinary searchNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a string SS of lowercase letters. Write a program that processes the following queries in order.

  • index len: print the number of palindromic substrings of SS that start at character index and have length at least len.

A palindrome is a string that reads the same forward and backward. The string of length 0 is also a palindrome, so when len is 0 the substring of length 0 starting at index counts as one more palindrome.

Input

The first line contains the string SS. Its length is at most 100,000, and it consists only of lowercase English letters.

The second line contains the number of queries MM (1M100,0001 \le M \le 100{,}000).

Each of the next MM lines contains one query, given as two integers index and len (0index<S0 \le index < |S|, 0len100,0000 \le len \le 100{,}000).

String indices start at 0.

Output

Print the answer to each query on its own line, in the order the queries are given.