#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

string s;

ll cnt[100005]['z'-'a'+5],t='z'-'a',q,l,r,f,sm,k,fc[100005],mod=1e9+7,ans,inv[100005];

ll pwr(ll a, ll p){
    if(p==0) return 1;
    if(p%2) return (pwr(a,p-1)*a)%mod;
    ll t=pwr(a,p/2);
    return (t*t)%mod;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> s; fc[0]=1; inv[0]=1;
    for(int i=0;i<s.lg;i++){
        for(int j=0;j<=t;j++){
            cnt[i+1][j]=cnt[i][j];
        }
        cnt[i+1][s[i]-'a']++;
        fc[i+1]=fc[i]*(i+1)%mod;
        inv[i+1]=pwr(fc[i+1],mod-2);
    }
    cin >> q;
    for(int i=1;i<=q;i++){
        cin >> l >> r; sm=0; k=0;
        ans=1;
        for(int j=0;j<=t;j++){
            f=cnt[r][j]-cnt[l-1][j];
            if(f%2) k++,f--;
            sm+=f;
            ans*=inv[f/2]; ans%=mod;
        }
        if(!k) k++;
        ans*=fc[sm/2]; ans%=mod;
        ans*=k; ans%=mod;
        cout << ans << '\n';
    }
}