import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void initialize(String s) { // This function is called once before all queries. } static int answerQuery(int l, int r, String s) { // Return the answer for this query modulo 1000000007. String ch=s.substring(l-1,r); int no=(r-l+1); HashMap map=new HashMap<>(); for(int i=0; i=2) { int num=no/2; int i=0; Set> entry=map.entrySet(); for(Map.Entry ent: entry) { if(ent.getValue()>=2) { i++; } } if(i>=num) { if(map.size()==i) return i; else return map.size()-i; } no--; } return 0; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); // initialize(s); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); int result = answerQuery(l, r, s); System.out.println(result); } in.close(); } }