#include #define ll long long #define int long long #define ss string #define pb push_back #define rev(i,n) for(ll i=0;i=0;i--) #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define all(v) v.begin(),v.end() #define S second #define F first #define tci(v,i) for(auto i=v.begin();i!=v.end();i++) #define MOD 1000000007 #define lld long double #define TIMESTAMP cerr<<(((double)clock())/CLOCKS_PER_SEC) #define rep(i,start,lim) for(ll (i)=(start);i<(lim);i++) using namespace std; ll aa[100005][27]; ll fac[100005],ch[27]; int power(int x, unsigned int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } int32_t main() { sync; fac[0]=1; rev(i,100000){fac[i+1]=fac[i]*(i+1);fac[i+1]%=MOD;} ss a;cin>>a; rev(i,a.length()) { aa[i+1][a[i]-'a'+1]++; } rev(i,a.length()-1) { for(ll j=1;j<=26;j++) aa[i+2][j]+=aa[i+1][j]; } ll q;cin>>q;ll k=0; while(q--) { ll l,r,s=1,p=0,ans,un;cin>>l>>r; rev(i,26) { ch[i+1]=aa[r][i+1]-aa[l-1][i+1]; } for(ll i=0;i<26;i++) { // cout<