#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pii pair< ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define mxn 2000002
#define sqr 320
map <char,ll> my [100005];
ll fact [100002];
ll power(ll x, ll y)
{
  ll p =mod;
    ll 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;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
     string s;
     cin>>s;
    ll i;
    fact[0]=1;
    for(i=1;i<100002;i++)
    {
     fact[i]=(i*fact[i-1])%mod;
    }
    for(i=0;i<s.size();i++)
    {
      my[i+1]=my[i];
      my[i+1][s[i]]++;
    }
    ll q;
    cin>>q;
    while(q--)
    {
      ll l,r,flg=0,ans=0;
      cin>>l>>r;
      vector<ll>v;
      for(i=0;i<26;i++)
      {
        ll io = my[r]['a'+i]-my[l-1]['a'+i];
        if(io%2) flg++;
        v.pb(io/2);
        ans+=io/2;
      }
      if(flg==0) flg=1;
     //   cout<<fact[ans]<<endl;
      ll kk = fact[ans];
      for(i=0;i<v.size();i++)
      {
        kk = (kk*power(fact[v[i]],mod-2))%mod;
      }
      cout<<(flg*kk)%mod<<endl;
    }
    return 0;
    }