#!/bin/python import sys stringa = "" def initialize(s): # This function is called once before all queries. stringa = s def answerQuery(s,l, r): # Return the answer for this query modulo 1000000007. sub = s[l-1:r] #print s,sub dic = {} for c in sub: n = dic.get(c,0) dic.update({c:n+1}) #print sub,dic len = 0 totlen = 0 for k in dic: n = dic.get(k) totlen += int(n / 2) if n %2 == 1: len = 1 return totlen + len if __name__ == "__main__": s = raw_input().strip() initialize(s) q = int(raw_input().strip()) for a0 in xrange(q): l, r = raw_input().strip().split(' ') l, r = [int(l), int(r)] result = answerQuery(s,l, r) print result