#!/bin/python3 import sys def initialize(s): # This function is called once before all queries. pass def answerQuery(l, r): # Return the answer for this query modulo 1000000007. b=s[l-1:r:1] flag1,flag2=0,0 a={} for i in b: a[i]=b.count(i) c1,c2=0,0 for i in a.values(): if(i==1): c2+=1 if(i>1): if(i%2==0): flag1=1 c1=c1+i//2 elif(i%2!=0): c1=c1+i//2 c2+=1 if(flag1==1): if(c2==0): return c1 else: return c2 if __name__ == "__main__": s = input().strip() initialize(s) q = int(input().strip()) for a0 in range(q): l, r = input().strip().split(' ') l, r = [int(l), int(r)] result = answerQuery(l, r) print(result)