import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class Node{ int[] arr; Node(){ arr = new int[26]; for(int i=0;i<26;i++) arr[i] = 0; } } public class Solution { static int[] fact; static Node[] initialize(String s) { int n = s.length(); int mod = 1000000007; Node[] list = new Node[n]; fact = new int[50001]; fact[0] = 1; for(int i=1;i<50001;i++){ fact[i] = (fact[i-1]*i)%mod; } list[0] = new Node(); Node temp = list[0]; temp.arr[s.charAt(0)-'a']++; for(int i=1;imax) max = arr[i]; } int count = 0; if(max==Integer.MIN_VALUE) for(int i=0;i<26;i++) if(arr[i]>max) max = arr[i]; int perm = 0; for(int i=0;i<26;i++){ if(arr[i] == max) count++; arr[i] = arr[i]/2; perm += arr[i]; } int res = 0; if(max%2==1){ res = fact[perm+1]; for(int i=0;i<26;i++){ if(arr[i]!=0) res = (res*power(fact[arr[i]],mod-2,mod))%mod; } res = (res*count)%mod; } else{ res = fact[perm]; for(int i=0;i<26;i++){ if(arr[i]!=0) res = (res*power(fact[arr[i]],mod-2,mod))%mod; } } return res; } static int power(int x, int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y%2==1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); Node[] list = 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,list); System.out.println(result); } in.close(); } }