#include <iostream>
#include <string>
#include <vector>

int main() {
	std::string word;
	std::vector<int>diap_begin;
	std::vector<int>diap_end;
	int Q = 0;
	{
		std::cin >> word >> Q;

		for (int i = 0;i < Q;i++) {
			int beg;
			int end;
			std::cin >> beg >> end;
			diap_begin.push_back(beg - 1);
			diap_end.push_back(end - 1);
		}
	}

	{
		std::string wordd;
		for (int q = 0;q < Q;q++) {
			wordd = word;
			wordd.erase(0, diap_begin[q]);
			wordd.erase(diap_end[q]- diap_begin[q]+1,wordd.size());
			
			int numWords = 1;
			for (int i = 1;i < wordd.size();i++) {
				if (wordd[i - 1] > wordd[i]) {
					numWords++;
				}
			}

			std::cout << numWords << '\n';

		}
	}
}
