program ab;
var
  s,ts:string;
  n,l,r,i,j,a,b,x,cur:int64;
begin
  readln(s);
  readln(n);
  for i:=1 to n do begin
    readln(l,r);
    cur:=1;
    ts:=copy(s,l,r-l+1);
    //writeln(ts);
    for j:=2 to length(ts) do begin
      if ts[j] < ts[j-1] then inc(cur);
    end;
    writeln(cur);
  end;
end.