import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void initialize(String s) { str = s; } static int answerQuery(int l, int r) { String s = str.substring(l+1, r); int n = s.length(); int data[] = new int[26]; for(int i = 0; i< n; i++) { int v = s.charAt(i) - 'a'; data[v]++; } int cOdd = 0 ; int cEven = 0 ; for(int i = 0; i< 26; i++) { if(data[i] != 0 && data[i] %2 == 0) { cEven += data[i]; } else if(data[i] >2) { cEven += (data[i] -1); } else if(data[i] > 0) { cOdd ++; } } cEven /= 2; long result = factorial(cEven); result = result % 1000000007; if(cOdd > 1) { result *= cOdd; } // Return the answer for this query modulo 1000000007. return (int)result; } static long factorial(long n){ if (n == 0) return 1; else { long v = factorial(n-1) % 1000000007L; return(n * v); } } static String str; 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(); } }