#Lutece2422. Nico~Nico~Ni~ (Ⅲ)

Nico~Nico~Ni~ (Ⅲ)

Migrated from Lutece 2422 Nico~Nico~Ni~ (Ⅲ)

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

这次的 鬼畜视频 可以用一个仅包含小写英文字母的字符串 SS 来表示。

定义一个字符串 TT 的鬼畜度为 TTSS 中的出现次数除以 TT 的长度。

作为一名计数菌,你将进行 nn 次计数。每次计数你都会选择两个正整数 L,RL, R,并计算 SS 的所有子串中字典序在 [L,R][L, R] 之间的子串的鬼畜度之和。

Input

第一行包含一个仅由小写英文字母构成的字符串 SS

第二行包含一个正整数 nn,表示计数的次数。

接下来有 nn 行,其中第 ii 行包含两个正整数 Li,RiL_i, R_i

Output

输出 nn 行,第 ii 行一个整数 xix_i,表示第 ii 次计数的答案。

设你计算的鬼畜度之和可以用既约分数 pq\displaystyle \frac{p}{q} 表示,你需要输出它模 109+710^9 + 7 的结果,即输出 pq1mod(109+7)p \cdot q^{-1} \bmod (10^9 + 7),其中 q1q^{-1} 表示 qq 在模 109+710^9 + 7 意义下的逆元。

Samples

niconiconi
2
2 3
10 45
3
92460351

Constraints

1S2×1051 \leq |S| \leq 2 \times 10^5

1n2×1051 \leq n \leq 2 \times 10^5

$\displaystyle 1 \leq L_i \leq R_i \leq \frac{n (n+1)}{2} \ \ (1 \leq i \leq n)$

Resources

2020 UESTC ICPC Training for String and Search Algorithm