import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String string; static void initialize(String s) { // This function is called once before all queries. string = s; } static int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. String str = string.substring(l - 1, r); long answer = 0; int[] alphas = new int[26]; for (int i = 0; i < str.length(); i++) { alphas[str.charAt(i) - 'a']++; } /* Find max length */ int numLetters = 0; int numSingles = 0; int maxLength = 0; for (int i = 0; i < alphas.length; i++) { if (alphas[i] == 1) { numSingles++; } else if (alphas[i] > 1) { if (alphas[i] % 2 == 0) { numLetters += alphas[i]; } else { numLetters += alphas[i] - 1; numSingles++; } } alphas[i] = alphas[i] / 2; } maxLength = numLetters; if (numSingles > 1) { maxLength++; } /* End find max length */ answer = factorial(maxLength / 2); long divisor = 0; for (int i = 0; i < alphas.length; i++) { if (alphas[i] > 0) { if (divisor == 0) { divisor = factorial(alphas[i]); } else { divisor *= factorial(alphas[i]); } } } answer = answer / divisor; answer = answer % 1000000007; return (int) answer; } static long factorial(long input) { if (input == 1) return 1; return input * (factorial(input - 1)); } 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(); } }