import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String input; static void initialize(String s) { input = s ; } static int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. String process = input.substring(l-1,r); int n = process.length(),len=0; int[] array = new int[26]; for(int i = 0 ; i < n ;i++) { array[process.charAt(i)-97]++; } int flag =0; for(int i = 0 ; i < 26 ;i++) { if( array[i]%2 == 0 ) { len += array[i]; } else if(array[i] % 2 == 1 && flag == 0 ) { len++; flag=1; } } return len-1; /* while(true) { int temp = len , flag = 0 ; for( int i = 0 ; i < len ; i++ ) { if( array[i]%2 == 0 && array[i] != 0 ) { temp--; } else if(array[i] % 2 == 1 && flag == 0 ) { temp--; flag=1; } } if(temp == 0 ) { count++; break; } } */ } 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(); } }