#!/bin/python3 import sys def answerQuery(l, r): # This function is called once before all queries. count_dict = {} for i in range(l,r): if s[i-1] in count_dict: count_dict[s[i-1]] += 1 else: count_dict[s[i-1]] = 1 count = 0 for i in count_dict: if count_dict[i] % 2 == 0: count += 1 max_len = count + 1 return max_len # Return the answer for this query modulo 1000000007. if __name__ == "__main__": s = input().strip() 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)