import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static String k; static void initialize(String s) { k=s; } static int answerQuery(int l, int r) { k = k.substring(l-1,r); int n = checkPali(k) - 1; return n; } private static int checkPali(String str) { String[] strar = str.split(""); List list = Arrays.asList(strar); list = list.subList(1, list.size()); Set set = new HashSet<>(list); String paliString = null; for (int i = 0; i < list.size(); i++) { paliString = list.get(i); for (int j = i + 1; j < list.size(); j++) { paliString = paliString + list.get(j); if (checkIfPalindrome(paliString)) { set.add(paliString); } } } return set.size(); } private static boolean checkIfPalindrome(String str) { char[] chars = str.toCharArray(); for (int i = 0; i < (chars.length / 2); i++) { if (chars[i] != chars[chars.length - 1 - i]) { return false; } } return true; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); initialize(s); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); int result = answerQuery(l, r); System.out.println(result); } in.close(); } }