import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static int matrix[][]; static void initialize(String s) { matrix = new int[s.length()][26]; for(int i=0; i0; j++){ matrix[i][j] = matrix[i-1][j]; if(j == (s.charAt(i)-'a')){ matrix[i][j]++; } } } } static int answerQuery(int l, int r) { if(l>r) return 0; if(l==r) return 1; long max = 0; boolean isodd = ((l-r)%2==0); for(int i=0; i<26; i++){ long difference = matrix[r][i] - (l==0 ? 0 : matrix[r-1][i]); if((isodd && difference%2==1) || difference%2==0){ if(difference > max) max = difference; } } if(isodd && max % 2 == 0){ //odd, can add a letter max++; } return (int)(max % 1000000007); } 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(); } }