问题3160--Fibonacci1

3160: Fibonacci1

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

The Fibonacci Numbers {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...} are defined by the recurrence: F(0)=0 F(1)=1 F(n)=F(n-1)+F(n-2) We defined S(n)=1+2+3+...+F(n). Write a program to calculate S(n). The result may be large,just output S(n)%m instead.

输入

The first line of the input file contains a single integer T<=100, the number of test cases. The following T lines,each contains two integer n ( 1 <= n <= 1000,000,000 )and m (0 < m <= 100,000,000), and you are expected to calculate S(n)%m.

输出

Output S(n)%m on a separate line.

样例输入 Copy

2
1 100
3 100

样例输出 Copy

1
3

来源/分类