#!/bin/python import sys from collections import Counter from math import factorial as fac def initialize(s): # This function is called once before all queries. dict1=Counter(s) return dict1 def answerQuery(l,r,dict1): # Return the answer for this query modulo 1000000007. c=0 flag=0 for a in dict1.keys(): if dict1[a]>=2: if dict1[a]%2==0: c+=(dict1[a])/2 dict1[a]=dict1[a]%2 else: c+=(dict1[a]-1)/2 dict1[a]=dict1[a]%2 elif dict1[a]<2 and dict1[a]>0: flag=1 num=fac(c) if flag==0: return num%(1000000007) elif flag==1: return (num+1)%(1000000007) if __name__ == "__main__": s = raw_input().strip() s2=list(s) q = int(raw_input().strip()) for a0 in xrange(q): list1 = map(int,raw_input().strip().split(' ')) l=list1[0] r=list1[1] dict1=initialize(s2[l-1:r]) l, r = [int(l), int(r)] result = answerQuery(l,r,dict1) print result