#!/bin/python3 import sys from collections import Counter debug = False def initialize(s): # This function is called once before all queries. pass def answerQuery(l, r): # Return the answer for this query modulo 1000000007. # 10**9 + 7 word = s[l-1:r] c = Counter(word) total = 0 for k, v in c.items(): if v % 2 == 1: v -= 1 total += v total /= 2 if 1 in c.values(): total += 1 return int(total) if __name__ == "__main__": s = input().strip() if not debug else 'abab' initialize(s) q = int(input().strip()) if not debug else 1 for a0 in range(q): l, r = input().strip().split(' ') if not debug else (1,4) l, r = [int(l), int(r)] result = answerQuery(l, r) print(result)