#include using namespace std; #define mod 1000000007 int has[100005][27]={0}; long long fact[1000005]={0}; void initialize(string s) { // This function is called once before all queries. fact[0]=1; for(int i=1;i<=100000;i++) { fact[i]=(fact[i-1]*i)%mod; } for(int i=0;i=2) { if(val%2!=0) odds++; evens+=val/2; reppro=(fact[val/2]*reppro)%mod; } } } long long ans=fact[evens]; if(odds!=0) ans=(ans*odds)%mod; // printf("ans: %lld rep: %lld\n",ans,reppro); return (inversemod(reppro,mod-2)*ans)%mod; } 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; long long result = answerQuery(l-1, r-1,s); cout << result << endl; } return 0; }