#include using namespace std; int answerQuery(int l, int r,string s) { // Return the answer for this query modulo 1000000007. unordered_map m; for (int i = 0; i < s.length(); i++) { // check for odd length palindromes for (int j = 0; j <= i; j++) { if (!s[i + j]) break; if (s[i - j] == s[i + j]) { // check for palindromes of length // greater than 1 if ((i + j + 1) - (i - j) > 1) m[s.substr(i - j, (i + j + 1) - (i - j))]++; } else break; } // check for even length palindromes for (int j = 0; j <= i; j++) { if (!s[i + j + 1]) break; if (s[i - j] == s[i + j + 1]) { // check for palindromes of length // greater than 1 if ((i + j + 2) - (i - j) > 1) m[s.substr(i - j, (i + j + 2) - (i - j))]++; } else break; } } return m.size(); } int main() { string s; cin >> 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; }