import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int q = in.nextInt(); long mod=1000000007,result=1; for(int a0 = 0; a0 < q; a0++) { int l = in.nextInt(); int r = in.nextInt(); int even=0,odd=0; String sub=s.substring(l-1,r); //System.out.print(sub); HashMap charCountMap = new HashMap(); char[] strArray = sub.toCharArray(); for (char c : strArray) { if(charCountMap.containsKey(c)) { charCountMap.put(c, charCountMap.get(c)+1); } else { charCountMap.put(c, 1); } } for (char c : charCountMap.keySet()) { int cnt=charCountMap.get(c); if(cnt%2==0) { even+=cnt/2; } else if(cnt%2!=0 && cnt>2) { even+=(cnt/2); odd++; } else { odd++; } } //for ( int c = 1 ; c <= odd; c++ ) //esult= result*c; for ( int c = 1 ; c <=even; c++ ) result= result*c; result*=odd; result =result % mod; System.out.println(result); } in.close(); } }