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