#!/bin/python3 import sys import math #def initialize(s): # This function is called once before all queries. def answerQuery(l, r, s): # Return the answer for this query modulo 1000000007. ss = s[l-1:r] su = set(ss) o = -1 c = 0 for a in list(su): acount = ss.count(a) if acount == 1 and o < 0: o += 1 continue c += math.ceil(acount/2) return c 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)