#include using namespace std; int dp[26][100001]; long long int fact[100001], ifact[100001]; long long int power(long long int x, unsigned int y, unsigned int m) { if (y == 0) return 1; long long int p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } long long int modInverse(long long int a, long long int m) { return power(a, m-2, m); } void initialize(string s) { for(int i=0;s[i];i++) { for(int j=0;j<26;j++) { dp[j][i+1] = dp[j][i]; } dp[s[i]-'a'][i+1] = dp[s[i]-'a'][i] + 1; } fact[0] = 1; ifact[0] = 1; for(int i=1;i<=100000;i++) { fact[i] = (fact[i-1]*i)%1000000007; ifact[i] = (ifact[i-1]*modInverse(i, 1000000007))%1000000007; } //for(int i=0;i<10;i++) cout<> 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; }