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) { String s_ = s.substring(l-1,r); char[] ch=s_.toCharArray(); Map map = new HashMap<>(); for (char c : ch) { map.put(c, map.getOrDefault(c,0) + 1); } List odd = new ArrayList<>(); Set evenSet = new HashSet<>(); int maxOdd = Integer.MIN_VALUE; for (Map.Entry entry : map.entrySet()) { if (entry.getValue()%2 == 0) { evenSet.add(entry.getKey()); } else { odd.add(entry.getValue()); maxOdd = Math.max(maxOdd, entry.getValue()); } } int countMaxOdd = 0; for (int n : odd) { if (n == maxOdd) countMaxOdd++; } return countMaxOdd != 0 ? ((countMaxOdd%1000000007)*(evenSet.size()%1000000007))%1000000007: evenSet.size()%1000000007; } 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); System.out.println(result); } in.close(); } }