import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import org.apache.commons.lang3.StringUtils; public class Solution { static String fullString; static void initialize(String s) { // This function is called once before all queries. fullString = s; } static int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. String subString = fullString.substring(l, r); int even = 0; int odd = 0; for( int i = 0; i < subString.length(); i++){ String currentChar = String.valueOf(subString.charAt(i)); int count = StringUtils.countMatches(subString, currentChar); String checkedChars = ""; if(!checkedChars.matches(currentChar)){ even = even + ( count / 2 ); if(count%2 == 1){ odd++; } checkedChars = checkedChars + currentChar; } } long result = (long) Math.pow(2, (even / 2) ); if(odd != 0){ result = result * odd; } int modulo = (int) result%1000000007; return modulo; } 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(); } }