#include using namespace std; string S; void initialize(string s) { // This function is called once before all queries. S = s; } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. int len = r-l+1; if (len == 1) { return 1; } string s = S.substr(l-1, len); if (len == 2) { return s[0] == s[1] ? 1 : 2; } map count; for (int i =0; i < s.size(); i++) { if (count.find(s[i]-'a') != count.end()) { count[s[i]-'a']++; } else { count[s[i]-'a'] = 1; } } long odd = 0; long even = 0; for (int i = 0; i < count.size(); i++) { if (count[i] & 1) odd++; } //cout << "odd=" << odd << endl; even = (len - odd)/2; //cout << "even=" << even << endl; if (even < 3) { return odd != 0 ? even * odd : even; } long res = (even/2 + even*even/2) % 1000000007; if (odd != 0) res = res*odd%1000000007; return res; } 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; }