import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static int fact(int n){ if(n==1&&n==0) return 1; else { int mul=1; for(int i=2;i<=n;i++){ mul=mul*i; } return mul; } } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); String New=s.substring(l-1,r); int count[]=new int[26]; for(int i=0;i