#!/bin/python3 import sys def initialize(s): pass # This function is called once before all queries. def answerQuery(l, r,s): k=s[l-1:r+1] m=dict() f=0 j=0 for i in k: if i not in m: m[i]=1 else: m[i]+=1 for i in m.values(): if i%2 !=0: j+=1 else: i=i//2 f+=i if j!=0: return f+j-1 else: return f # Return the answer for this query modulo 1000000007. 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,s) print(result)