import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int answerQuery(int l, int r,String s) { // Return the answer for this query modulo 1000000007. int c=0; int d; for(int i=l-1;i<=r-1;i++){ for(int j=l-1;j<=r-1;j++){ if(s.charAt(i)==s.charAt(j)){ c++; } } } if(c==0) d=0; else if(c>0&&(r-(l-1)==c/2)){ d=(r-(l-1))/2; } else if(c/2==(r-(l-1))) d=(r-(l-1))/2; else{ d=c/2; } return d; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); int result = answerQuery(l, r, s); System.out.println(result); } in.close(); } }