import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int l=1000000007; static int f[]=new int[41]; static int fact(int e) { if(e>40) return 0; else return f[e]; } static void initialize(String s) { // This function is called once before all queries. } static int answerQuery(String s,int l, int r) { // Return the answer for this query modulo 1000000007. int c[]=new int[26]; int odd=0,even=0; for(int i=0;i<26l;i++) c[i]=0; String ne=s.substring(l-1,r); for(int i=0;i1) {odd++;--c[i];even+=c[i]/2;} else odd++; } if(odd!=0) return ((odd%l)*(fact(even)))%l; return (fact(even)); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); initialize(s); int q = in.nextInt(); f[0]=0; for(int i=1;i<41;i++) { f[i]=1; for(int j=i;j>=1;j--) f[i]=((f[i]%l)*(j%l))%l; } for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); int result = answerQuery(s,l, r); System.out.println(result); } in.close(); } }