#include #include #include #include #include #define ll long long #define D 1000000007 using namespace std; vector f(1,1); ll fact(ll x){ if(x>=f.size()){ fact(x-1); f.push_back((fact(x-1)*x)%D); } return f[x]; } ll ppow(ll a, ll b){ if(b==0) return 1; if(b%2 == 0) return ppow((a*a)%D, b/2); else return (ppow((a*a)%D, b/2)*a)%D; } ll inv(ll n){ return ppow(n, D-2); } int main() { ll q, l, r, n; string s; cin >> s >> q; n = s.size(); vector > oui(n+1, vector (26,0)); vector foo(26,0); for(ll i = 0; i> l >> r; for(ll c = 0; c<26; ++c){ ll bar = (oui[r][c] - oui[l-1][c]); tot += (bar/2); if(bar%2==1) b += 1; } for(ll c = 0; c<26; ++c){ ll bar = ((oui[r][c] - oui[l-1][c])/2); ll caca = ((fact(tot) * inv(fact(bar)))%D * inv(fact(tot-bar)))%D; tot -= bar; res = (res*caca)%D; } if(b!=0) res = (res*b)%D; cout << res << endl; } return 0; }