#!/bin/python3 import sys def fact(n): if n == 1: return 1 else: ans= n* fact(n-1) return ans def answerQuery(s,l, r): d = {} str = s[l-1:r] for c in str: if c in d: d[c]+=1 else: d[c]=1 twos = 0 ones = 0 for k,v in d.items(): if v%2==0: twos += v//2 else: ones+= v%2 twos+= v//2 if ones ==0: ans = fact((twos)) else: ans = fact((twos))*ones return ans if __name__ == "__main__": s = input().strip() q = int(input().strip()) for a0 in range(q): l, r = input().strip().split(' ') l, r = [int(l), int(r)] result = answerQuery(s,l, r) print(result)