#include using namespace std; string s1; void initialize(string s1) { // This function is called once before all queries. } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. string s; s=s1.substr(l-1,r-l+1); if (s.empty()) return 0; if (s.size() == 1) return 1; int min_start = 0, max_len = 1; for (int i = 0; i < s.size();) { if (s.size() - i <= max_len / 2) break; int j = i, k = i; while (k < s.size()-1 && s[k+1] == s[k]) ++k; // Skip duplicate characters. i = k+1; while (k < s.size()-1 && j > 0 && s[k + 1] == s[j - 1]) { ++k; --j; } // Expand. int new_len = k - j + 1; if (new_len > max_len) { min_start = j; max_len = new_len; } } return (s.substr(min_start, max_len).size())%1000000007; } int main() { cin >> s1; initialize(s1); 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; }