import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { /* 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 length=0; int n = r-l; int count[] = new int[n]; for(int i=l-1;i<=r-1;i++){ for(int j=l-i;j<=r-1;j++){ if(s.charAt(i) == s.charAt(j)){ count[i]++; } if(count[i]%2==0){ length = length + facto(count[i]); } else{ length = length + count[i]; } } } return(length); } static int facto(int n){ int fact=1; for(int i=n;i>0;i++){ fact = fact*i; } return(fact); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); int result = answerQuery(s,l, r); result = result%1000000007; System.out.println(result); } in.close(); } }