import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int tab[][]; static long fact[]; //calculate a pow b mod m public static long powMod(long a, long b, long m){ long res = 1L; while(b != 0){ if((b & 1) == 1) res = res * a; res %= m; a = a * a; a %= m; b >>= 1; } return res; } //Retrun the inverse module (the m must be a prime) public static long invModPrime(long a, long m){ return powMod(a, m - 2, m); } static void initialize(String s) { // This function is called once before all queries. tab = new int[s.length() + 1][26]; for(int i = 1; i <= s.length(); i++){ tab[i][s.charAt(i - 1) - 'a'] += 1; for(int j = 0; j < 26; j++) tab[i][j] += tab[i - 1][j]; } fact = new long[100001]; fact[0] = 1; for(int i = 1; i <= 100000; i++){ fact[i] = fact[i - 1] * i; fact[i] %= 1000000007; } } static long answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. int t[] = new int[26]; for(int i = 0; i < 26; i++) t[i] = tab[r][i] - tab[l - 1][i]; int even = 0, odd = 0; long div = 1L; for(int i = 0; i < 26; i++){ if(t[i] > 1){ even += t[i] / 2; odd += t[i] % 2; div = div * fact[t[i] / 2]; div %= 1000000007; } else if(t[i] == 1) odd++; } long res = fact[even]; res = (res * invModPrime(div, 1000000007)) % 1000000007; if(odd > 0) res = (res * odd) % 1000000007; return res; } 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(); long result = answerQuery(l, r); System.out.println(result); } in.close(); } }