#!/bin/python import sys def initialize(s): # This function is called once before all queries. return s def answerQuery(l, r, ss): # Return the answer for this query modulo 1000000007. nol = dict() for l in ss: if l not in nol: nol[l] = 1 else: nol[l] += 1 nol_c = {k: v / 2 for k,v in nol.items() if v / 2 > 0} cc = sum(nol_c.values()) + 1 return cc 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(l, r, s[l:r+1]) print result