const al = 'abc';

var q, i:longint;
    l, r:array[1..100000]of longint;
    s:ansistring;


function f(i:longint):longint;
var j:longint;
begin

  f:=0;
  for j:=l[i]+1 to r[i] do 
    if pos(s[j], al)<pos(s[j-1], al) then
      inc(f); 

end;


begin
  read(s);
  read(q);

  for i:=1 to q do read(l[i], r[i]);

  for i:=1 to q do writeln(f(i)+1);

end.
