#include #include #include #include #include #include #include #define MOD 1000000007 long int factorial(int n) { if(n==1) return 1; return n*factorial(n-1); } void initialize(char* s) { // This function is called once before all queries. } int answerQuery(int l, int r, char *s) { // Return the answer for this query modulo 1000000007. int arr[26] = {0}; for(int i = l-1; i < r; i++) { arr[s[i] - 'a']++; } int d[26] = {0}; int count = 0, sa = 0; for(int i = 0; i < 26; i++) { int n = (int)(arr[i] / 2); if(n > 0) { d[i] = n; count = count + n; if(arr[i] % 2 != 0) { sa++; } } if(arr[i] == 1) { sa++; } } long long int num = 0; num = factorial(count) % MOD; for(int i = 0; i < 26; i++) { if(d[i] != 0) { num = num / factorial(d[i]); } } int a = (num * sa) % MOD; return a; } int main() { char* s = (char *)malloc(512000 * sizeof(char)); scanf("%s", s); initialize(s); int q; scanf("%i", &q); for(int a0 = 0; a0 < q; a0++){ int l; int r; scanf("%i %i", &l, &r); int result = answerQuery(l, r, s); printf("%d\n", result); } return 0; }