#include using namespace std; string temp; int mod = 1000000007; map fact; void initialize(string s) { // This function is called once before all queries. temp = s; } int ComputeFact(int n) { if(n <= 1) { return 1; } if(fact.find(n) != fact.end()) { return fact[n]; } int previous = ComputeFact(n - 1); int answer = ((previous % mod) * (n % mod) ) % mod ; fact.insert(make_pair(n, answer)); return answer; } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007 vector dp(26, 0); for(int i= l -1; i < r; ++i) { dp[temp[i] - 'a'] += 1; } int size = 0; int count = 0; for(int i=0; i < 26; ++i) { //cout << dp[i] << " "; if(dp[i] % 2 == 0) { count += 1; size += (dp[i] /2); } } int totalSize = ComputeFact(size); if(count == 1) { totalSize = (totalSize * 2) % mod; } return totalSize; } int main() { string s; cin >> s; initialize(s); int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; int result = answerQuery(l, r); cout << result << endl; } return 0; }