#include #define fo0(i,n) for(int i = 0;i < n; ++i) #define fo1(i,n) for(int i = 1;i <= n; ++i) #define mem(ar,num) memset(ar,num,sizeof(ar)) #define me(ar) memset(ar,0,sizeof(ar)) #define lowbit(x) (x&(-x)) using namespace std; typedef long long LL; typedef unsigned long long ULL; const int prime = 999983; const int INF = 0x7FFFFFFF; const LL INFF =0x7FFFFFFFFFFFFFFF; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-6; const LL mod = 1e9 + 7; //...................................................... using namespace std; const int maxn = 1e5+100; int alpha[26][maxn]; int fac[maxn]; void initialize(string s) { // This function is called once before all queries. // memset() for(int i = 0;i < s.size(); ++i) { alpha[s[i]-'a'][i]++; if(i!=0) for(int j = 0;j < 26; ++j) alpha[j][i] += alpha[j][i-1]; } fac[0] = 1; for(int i = 1;i <= maxn-1;++i) { fac[i] = (LL)fac[i-1]*i%mod; } } long long ext_gcd(long long a,long long b,LL &x,LL &y) { if(b==0) { x = 1,y = 0; return a; } LL m; m = ext_gcd(b,a%b,y,x); y -= a / b * x; return m; } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. int a[26]; me(a); l--,r--; int e,o; e = o = 0; for(int i = 0;i < 26; ++i) { if(l==0) a[i] = alpha[i][r]; else a[i] = alpha[i][r]-alpha[i][l-1]; } for(int i = 0;i < 26; ++i) { if(a[i]&1) o++; e += a[i]/2; } if(e==0) return o; LL ans = fac[e]; if(o!=0) ans = ans*o%mod; LL fenmu = 1; for(int i = 0;i < 26; ++i) { fenmu = fenmu * fac[a[i]/2]%mod; } LL x,y; ext_gcd(fenmu,mod,x,y); x = (x%mod+mod)%mod; return x*ans%mod; } int main() { string s; cin >> s; initialize(s); int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; int result = answerQuery(l, r); cout << result << endl; } return 0; }