import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static char[] str; static void initialize(String s) { str = s.toCharArray(); } static int answerQuery(int l, int r) { int map[] = new int[26]; for(int i =l-1; i < r-1; i++){ map[str[i] - 'a']++; } while(!isPal(map)){ turnToPallyTry(map); } return amountOfPal(map); } 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(); } static boolean isPal(int[] map){ boolean odd = false; for(int i =0; i < 26; i++){ if(map[i] % 2 == 1){ if(odd)return false; odd = true; } } return true; } static void turnToPallyTry(int[] map){ for(int i =0; i < 26; i++){ if(map[i] % 2 == 1){ map[i]--; return; } } } static int amountOfPal(int[] map){ int max = 0; for(int i =0; i < 26; i++){ max += map[i] / 2; } return max+1; } }