#!/bin/python3 import sys def count(s): count={} for i in s: if(i in count.keys()): count[i]+=1 else: count[i]=1 return count def answerQuery(l, r,s): string="" for i in range(1,len(s)+1): if(l<=i<=r): string+=s[i-1] cnt=count(string) count_multiple=0 count_even=0 base=0 count_single=0 for i in cnt.values(): if(i%2==0): count_even+=i elif(i>2): count_even+=(i-1) count_single+=1 else: count_single+=1 if(count_single!=0): max_len=count_even+1 else: max_len=count_even if(count_even!=0 and count_single==0): ans=1 elif(count_even!=0 and count_single!=0): ans=count_single else: ans=0 return ans%1000000007 # Return the answer for this query modulo 1000000007. if __name__ == "__main__": s = input().strip() #initialize(s) count(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)