You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.

String s[l... r] = slsl + 1... sr (1 ≤ l ≤ r ≤ |s|) is a substring of string s = s1s2... s|s|.

String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.

Input

The first line contains string s (1 ≤ |s| ≤ 5000). The second line contains a single integer q (1 ≤ q ≤ 106) — the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 ≤ li ≤ ri ≤ |s|) — the description of the i-th query.

It is guaranteed that the given string consists only of lowercase English letters.

Output

Print q integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.

Examples

Input

caaaba
5
1 1
1 4
2 3
4 6
4 5


Output

1
7
3
4
2

Note

Consider the fourth query in the first test case. String s[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba».
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;

public class ProblemH {
    
    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        
        char[] cl = s.readLine().toCharArray();
        int len = cl.length;
        char[][] sum = new char[len+1][len+1];
        for (int i = 0 ; i < len ; i++) {
            int l = 0;
            int left = i-1;
            int right = i+1;
            sum[l][i]++;
            while (left >= 0 && right < len) {
                l += 2;
                if (cl[left] != cl[right]) {
                    break;
                }
                sum[l][right]++;
                left--;
                right++;
            }
        }
        for (int i = 0 ; i < len-1 ; i++) {
            if (cl[i] != cl[i+1]) {
                continue;
            }
            int l = 1;
            int left = i-1;
            int right = i+2;
            sum[l][i+1]++;
            while (left >= 0 && right < len) {
                l += 2;
                if (cl[left] != cl[right]) {
                    break;
                }
                sum[l][right]++;
                left--;
                right++;
            }
        }
        
        int[][] diag = new int[len+2][len+2];
        {
            for (int x = 0 ; x < len ; x++) {
                int i = 0;
                int j = x;
                for (int y = 0 ; y < len ; y++) {
                    diag[i+1][j+1] += diag[i][j] + sum[i][j];
                    i++;
                    j++;
                    if (j >= len || i >= len) {
                        break;
                    }
                }
            }
            for (int j = 0 ; j < len ; j++) {
                for (int i = len ; i >= 1 ; i--) {
                    diag[i-1][j+1] += diag[i][j+1];
                }
            }
        }
        
        int q = Integer.valueOf(s.readLine());
        for (int i = 0 ; i < q ; i++) {
            String[] data = s.readLine().split(" ");
            int l = Integer.valueOf(data[0])-1;
            int r = Integer.valueOf(data[1])-1;
            
            long ans = diag[0][r+1] - diag[r-l+2][r+1];
            out.println(ans);
        }
        
        out.flush();
    }
    

    public static void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}