import sys word = None def initialize(s): global word word = s # This function is called once before all queries. def answerQuery(l, r): word_map = {} global word s = word[l:r+1] for x in s: if x in word_map: word_map[x] = word_map[x] + 1 else: word_map[x] = 1 n2 = 0 n1 = 0 for x in word_map: n = word_map[x] n2 = n2 + (n /2) n = n % 2 if n == 1: n1 = n1 + 1 longest_pallindrom = n2 if n1 > 0: longest_pallindrom = longest_pallindrom + 1 return longest_pallindrom % 1000000007 # Return the answer for this query modulo 1000000007. 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) print result