#include using namespace std; //void initialize(string s) { // This function is called once before all queries. //} int m=1000000007; int f(int a){ if(a==1)return 1; else return (a%m*(f(a-1)%m))%m; } int answerQuery(int l, int r, string s) { vector a; l--;r--; for(int i=l;i<=r;i++){ for(int j=l+1;j<=r;j++){ if(find(a.begin(),a.end(),i)==a.end()){ if(s[i]==s[j]){ a.push_back(j); } } } } if(a.size()==(r-l+1)/2){//cout<<1; return ((((r-l+1)%m)*((r-l)%m))/2)%m; } else {//cout<<2; int t=a.size(); return ((t%m*(t-1)%m)/2)+(r-l+1-2*t)%m; } // Return the answer for this query modulo 1000000007. } 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,s); cout << result << endl; } return 0; }