mod = 10**9 + 7 maxn = 10**5 + 1 fac = [1] * maxn ifac = [1] * maxn for i in range(2, maxn): fac[i] = fac[i-1] * i % mod ifac[-1] = pow(fac[-1], mod-2, mod) for i in range(maxn-1, 0, -1): ifac[i-1] = ifac[i] * i % mod def ncr(n, r): return fac[n] * ifac[r] % mod * ifac[n-r] % mod s = input().strip() n = len(s) chars = [[0] * (n+1) for _ in range(26)] for i in range(n): letter = ord(s[i]) - ord('a') chars[letter][i+1] = 1 for arr in chars: for i in range(1, len(arr)): arr[i] += arr[i-1] for q in range(int(input())): l, r = [int(x) for x in input().strip().split()] evens = [] odds = [] for i in range(26): freq = chars[i][r] - chars[i][l-1] if freq & 1 == 1: odds.append(freq >> 1) elif freq != 0: evens.append(freq >> 1) total = sum(evens)+sum(odds) ans = fac[total] for even in evens: ans = ans * ifac[even] % mod for odd in odds: ans = ans * ifac[odd] % mod ans = ans * max(1, len(odds)) % mod print(ans)