#include using namespace std; const long long int inf = 1000000007; vector > v(27,vector()); long long fact[100005], invfact[100005]; long long exp(long long a, long long b) { long long z = a; long long x = 1; while(b) { if(b%2) x = x*z%inf; z = z*z%inf; b>>=1; } return x; } void initialize(string s) { // This function is called once before all queries. for(int i = 0; i < s.size(); i++) v[s[i]-'a'].push_back(i); fact[0] = fact[1] = 1; for(int i = 2; i < 100005; i++) fact[i] = fact[i-1]*i%inf; invfact[100004] = exp(fact[100004],inf-2); for(int i = 100003; i >= 0; i--) invfact[i] = exp(fact[i],inf-2); //for(int i = 0; i < 10; i++) cout< mp; for(int i = 0; i < 27; i++) { int num = (upper_bound(v[i].begin(),v[i].end(),r-1) - lower_bound(v[i].begin(),v[i].end(),l-1)); //cout<<"num = "<second]%inf; if(h) ans = ans*h%inf; return ans; } 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; }