#Lutece3064. interval max border

interval max border

Migrated from Lutece 3064 interval max border

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,你需要回答 qq 次询问,每次询问给定一个区间,求 SS 在该区间的子串的最长 border 长度。

Border 的定义:若一个串 tt 同时是串 ss 的前缀和后缀,则 tt 被称为 ss 的 border。

Input

第一行一个字符串 SS

第二行一个整数 qq,表示询问个数。

随后的 qq 行,每行两个数 l,rl,r,表示询问的区间。字符串中字符的下标从 11 开始。

Output

qq 行,每行一个整数,表示对应询问的答案。

Samples

abbabbaa
3
1 8
1 7
2 7
1
4
3

Constraints

1lrS2×1051\le l\le r\le |S|\le 2\times 10^5 1q2×1051\le q\le 2\times 10^5

Resources

2023 UESTC ICPC Training for String