#P10954. [2015杭电多校]MZL's Border
[2015杭电多校]MZL's Border
MZL's Border
Problem Description
As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was playing with her favorite data structure, strings. MZL is really like , so she defines in the similar way. The definition of is given below.
- For instance, . Assume that a string whose length is is . Then is called as a substring of , which is written as . Assume that . If , then is called as a of . In of , the longest is called as ' . Moreover, 's is called as . Now you are given 2 numbers and . MZL wonders what of is. For the number can be very big, you should just output the number modulo . Note that $1\leq T\leq 100,~1\leq n\leq 10^3,~1\leq m\leq |fib_n|$.
Input
The first line of the input is a number , which means the number of test cases. Then for the following lines, each has two positive integers and , whose meanings are described in the description.
Output
The output consists of lines. Each has one number, meaning 's modulo .
Sample Input
2
4 3
5 5
Sample Output
1
2
Author
SXYZ
Source
2015 Multi-University Training Contest 5