#include using namespace std; int dp[100001][26]; #define ll long long #define MOD 1000000007 ll addMod(ll a, ll b, ll m) { if (a + b < 0) return (a - m) + b; else if (a + b >= m) return a + b - m; else return a + b; } ll multiplyMod(ll a, ll b, ll m) { if (b == 0 || a <=LLONG_MAX / b) return (a * b) % m; ll result = 0; if (a > b) swap(a,b); while (a > 0) { if ((a & 1) != 0) { result = addMod(result, b, m); } a >>= 1; b -= m - b; if (b < 0) b += m; } return result; } ll bigMod(ll b,ll p,ll m) { ll x=1,y=b%m; while(p>0) { if(p%2==1) { x=multiplyMod(x,y,m); } y=multiplyMod(y,y,m); p=p/2LL; } return x; } int main() { string s; cin>>s; setst; for(int i=0; i<26; i++) { dp[i][i]=0; } for(int i=1; i<=s.size(); i++) { int v=s[i-1]-'a'; for(int j=0; j<26; j++) { if(j==v) { dp[i][j]=dp[i-1][j]+1; } else { dp[i][j]=dp[i-1][j]; } } } int q; cin>>q; while(q--) { int l,r; cin>>l>>r; ll ev=0; ll od=0; for(int i=0; i<26; i++) { int v=dp[r][i]-dp[l-1][i]; if(v%2==0 && v>0)ev++; else if(v>0 && v%2==1)od=1; } ll ans=ev-1; if(od==1)ans=od/ev; ll res=bigMod(2LL,ans,MOD); if(res<0)res+=MOD; cout<