program zadacha2;
   var a,b,c:array [1..100001] of longint;
      s,s1,s2:ShortString;
      i,n,q,j,x,y:longint;
      l:integer;
begin
   s1:='';
   readln(s);
   q:=length(s);
   readln(n);
   for i:=1 to n do
      readln(a[i],b[i]);
   for i:=1 to q do
      begin
         if (s[i] = 'a') then
            s1:=s1+'1';
         if (s[i] = 'b') then
            s1:=s1+'2';
         if (s[i] = 'c') then
            s1:=s1+'3';
      end;
   for i:=1 to n do
      begin
         for j:=a[i]+1 to b[i] do
            begin
               val(s1[j],x,l);
               val(s1[j-1],y,l);
               if (x<>y)and(x<y) then c[i]:=c[i]+1;
            end;
         c[i]:=c[i]+1;
         writeln(c[i]);
      end;
end.