#!/bin/python3 import sys from collections import defaultdict from math import factorial #Q1 def canConstruct(a): # Return "Yes" or "No" denoting whether you can construct the required number. s = "".join(map(str,a)) s = list(map(int,s.split())) if (sum(s) % 3 == 0) and (sum(s) > 0): return "Yes" return "No" #Q2 def answerQuery(s, l, r): # Return the answer for this query modulo 1000000007. ss = s[l-1:r] d = defaultdict(int) ones = [] twoOrMores = [] for c in ss: d[c] += 1 for x in d: if d[x] > 1 and d[x] % 2 != 0: d[x] -= 1 twoOrMores.append(x) if d[x] == 1: ones.append(x) for key in ones: del d[key] l = ones + twoOrMores dlist = list(d.values()) m = 0 for x in dlist: if x > 1: m+= int(x/2) dlist = [int(x/2) for x in dlist] print(dlist) Sum = sum(dlist) allWays = factorial(Sum) ways = int(allWays/m) return ways * len(l) 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)