#include using namespace std; typedef unsigned long long int ll; #define MOD 1000000007 #define CLL static_cast int sum(vector arr){ int sum = 0; for(int i = 0; i < arr.size(); i++){ sum += arr[i]; } return sum; } ll fact(ll num){ if(num <= 1){ return num; } return num*fact(num-1); } int main() { string s; cin >> s; int q; cin >> q; for(int i = 0; i < q; i++){ int l, r; cin >> l >> r; string inp = s.substr(l-1, r-l+1); map freq; for(int j = 0; j < inp.length(); j++){ if(freq.find(inp[j]) == freq.end()){ freq[inp[j]] = 0; } freq[inp[j]]++; } int oddFreqCount = 0; vector evenFreq; for(auto it = freq.begin(); it != freq.end(); it++){ if(it->second%2 == 0){ evenFreq.push_back(it->second/2); } else { if(it->second-1 != 0){ evenFreq.push_back((it->second-1)/2); } oddFreqCount++; } } ll num = fact(CLL(sum(evenFreq))), den = 1; for(int j = 0; j < evenFreq.size(); j++){ den *= fact(CLL(evenFreq[j])); } cout << ((num/den)*(oddFreqCount == 0 ? 1 : oddFreqCount))%CLL(MOD) << endl; } return 0; }