#include using namespace std; #define ll long long int #define mod 1000000007 int main() { string str; cin>>str; int q; cin>>q; while(q--) { int l,r; cin>>l>>r; l--; r--; map mp; for(int i=l;i<=r;i++) { mp[str[i]]++; } int cnt2=0; int cnt1=0; int g=0; int mx=-1; char ch; for(auto it=mp.begin();it!=mp.end();it++) { if((it->second)>=2) cnt2++; if(it->second==1) cnt1++; cnt1=cnt1%mod; if((it->second)>=3) g+=(it->second)-2; cnt1=cnt1%mod; int h=it->second; if(h>mx) { ch=it->first; } } int ans=0; if(cnt1==0 && cnt2!=0) { for(auto i=mp.begin();i!=mp.end();i++) { if(i->second==mp[ch]) ans++; } cout<