//Jan 2, 2018 8:38:19 PM //Loki import java.math.BigInteger; import java.util.*; public class A { static int a[]; static long mv; static String str; public static void main(String[] asd) { Scanner s = new Scanner(System.in); str=s.next(); int q = s.nextInt(),l,r; String tmp; while (q-- > 0) { l=s.nextInt()-1; r=s.nextInt(); tmp=str.substring(l,r); a=new int[26]; mv=0; //System.out.println(str.substring(l,r)); mv=fill(tmp); System.out.println(ans()); } } static BigInteger mod=new BigInteger("1000000007"); static BigInteger f(long ii) { BigInteger ab=BigInteger.ONE; for(long i=2;i