#include using namespace std; typedef long long ll; int main() { string str; cin>>str; ll q; ll l=str.size(); cin>>q; while(q--) { ll l,r; cin>>l>>r; l--; r--; mapmp; ll mx=0; for(ll i=l;isecond; if(mx==now)cnt++; it++; } cout<<(cnt*mx)%1000000007<