import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String tocheck = ""; static void initialize(String s) { tocheck = s; } static int answerQuery(int l, int r) { int numofPalin = 0; String newStr = tocheck.substring(l, r); numofPalin = findrepeater(newStr); return numofPalin; // Return the answer for this query modulo 1000000007. } static int findrepeater(String s) { int distinct = 0; for (int i = 0; i < s.length(); i++) { for (int j = 0; j < s.length(); j++) { if (s.charAt(i) == s.charAt(j)) { distinct++; } } //System.out.println(s.charAt(i) + "--" + distinct); String d = String.valueOf(s.charAt(i)).trim(); s = s.replaceAll(d, ""); //distinct = 0; } return distinct; } 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(); } }