import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static final int MAX_SIZE = 100010; private static final int REM = 1000000007; private static int[][] count; private static int[] fact = new int[MAX_SIZE]; private static int[] rfact = new int[MAX_SIZE]; static int pow(int a, int b) { if (b == 0) {return 1;} if (b % 2 == 1) {return (int)((long)pow(a, b-1) * a % REM);} int mid = pow(a, b/2); return (int)((long)mid * mid % REM); } static void initialize(String s) { int len = s.length(); count = new int[26][len]; for (int i=0; i<=25; ++i) { char ch = (char)('a' + i); count[i][0] = (s.charAt(0) == ch ? 1 : 0); for (int j=1; j counts = new ArrayList<>(); int len = 0; for (int i=0; i<=25; ++i) { int cnt = count[i][r] - (l>0?count[i][l-1]:0); len += cnt / 2; counts.add(cnt); } int ans = 1; int odd_count = 0; for (int i=0; i<=25; ++i) { int cnt = counts.get(i); ans = (int)((long)ans * fact[len] % REM * rfact[cnt/2] % REM * rfact[len-cnt/2] % REM); len -= cnt/2; if (cnt % 2 == 1) {++odd_count;} } if (odd_count > 0) { ans = (int)((long)ans * odd_count % REM); } return ans; // Return the answer for this query modulo 1000000007. } 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(); } }