#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(v) ((v).begin()) , ((v).end()) #define sz(v) ((int)((v).size())) using namespace std; set st; set ::iterator it; map mp; map ::iterator itr; /*bool co(const pair&c, const pair&d) { return c.second > d.second; } */ int arr[100000] = { 0 }; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int n, r, l, p = 0, e = 0, o = 0; string s, str; cin >> s >> n; for (int i = 0; i < n; i++) { cin >> r >> l; str = s.substr(r - 1, l - r + 1); sort(str.begin(), str.end()); p = 0; arr[0] = 1; for (int j = 1; j < str.size(); j++) { if (str[j] == str[j - 1]) arr[p]++; else { if (arr[p] % 2 == 0) e++; else o++; p++; arr[p]++; } } if (arr[p] % 2 == 0) e++; else o++; if (o == 0 && e != 0) cout << e << endl; else cout << min(e, o) * 2 << endl; e = 0, o = 0; } }