#include using namespace std; const int N=1e5+5; const int mod=1e9+7; string s; int t,l,r,f[N],p[N][30]; int poww(int x, int e){ int ret=1; while (e){ if (e&1){ ret=1ll*ret*x%mod; } x=1ll*x*x%mod; e>>=1; } return ret; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> s; for (int i=0;i<(int)s.size();i++){ for (int j=0;j<26;j++){ p[i][j]=(i?p[i-1][j]:0); if (s[i]-'a'==j){ p[i][j]++; } } } f[0]=1; for (int i=1;i<=(int)s.size();i++){ f[i]=1ll*f[i-1]*i%mod; } cin >> t; while (t--){ cin >> l >> r; l--,r--; int tot=0,ans=1,sin=0; for (int i=0;i<26;i++){ int now=p[r][i]-(l?p[l-1][i]:0); if (now&1){ sin++; } tot+=now/2; if (now/2){ ans=1ll*ans*poww(f[now/2],mod-2)%mod; } } ans=1ll*ans*f[tot]%mod; if (sin){ ans=1ll*ans*sin%mod; } cout << ans << "\n"; } }