import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String lol=""; static void initialize(String s) { // This function is called once before all queries. lol=s; } static int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. String s=lol.substring(l-1,r); int count[]=new count[26]; for(int i=0;ill=new LinkedList<>(); for(int i=0;i<26;i++) { if(count[i]%2==0) { f+=count[i]/2; } else { if(count[i]>odd) { odd=count[i]; odd_count=1; } else(count[i]==odd) { odd_count++; } } } f+=odd_count*(odd/2); return fact(f); } static int fact(int a) { if(a==0||a==1) return 1; return a*fact(a-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(); } }