import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class Main { static long[] fact, ifact; static long MOD = 1000000007; static void initialize(String s) { // This function is called once before all queries. A = new int[s.length()+1][26]; for(int i=0;i0) for(int j=0;j<26;j++){ A[i][j] = A[i-1][j]+ A[i][j]; } } fact = new long[100005]; ifact = new long[fact.length]; fact[0] = 1;ifact[0] = modI(1); for(int i=1;i0){ if(b%2==1){ res = (res*a)%MOD; } b/=2; a = (a*a)%MOD; } return res; } static int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. int[] C = new int[26]; for(int i=0;i<26;i++){ C[i] = A[r-1][i]; if(l>1){ C[i] -= A[l-2][i]; } } int odd = 0, maxlength = 0; for(int i=0;i<26;i++){ if(C[i]%2==1){ odd++; } maxlength += (C[i]/2)*2; } maxlength+=odd>0?1:0; long res = Math.max(1, odd); // System.out.println(odd+" "+res); int poss = maxlength/2; res = (res * fact[poss])%MOD; // System.out.println(res); for(int i=0;i<26;i++){ int count = (C[i]/2); res = (res * ifact[count])%MOD; // System.out.println(count+" "+res); } // System.out.println(maxlength+" "+poss+" "+res); return (int)(res%MOD); } static int[][] A; 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(); } }