const al = 'abc';

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


begin
  read(s);
  read(q);

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

  for i:=1 to length(s) do 
    if pos(s[i], al)<pos(s[i-1], al) then p[i]:=true;
  
  for i:=1 to q do 
    begin
      k:=0;
      for j:=l[i]+1 to r[i] do 
        if p[j] then inc(k);
      writeln(k+1);
    end;

end.
