3362: Count

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:26 解决:12

题目描述

Many ACM team name may be very funny,such as "Complier_Error","VVVVV".Oh,wait for a minute here.

Is it "W W"+"V",or "W"+"V V V",or something others we can treat as?There are several ways we can treat this name "VVVVV" (5 'V's),as V V can be treat as a W.

For 5 'V's,our have 8 ways.They are:

1.      V      V      V     V     V

2.      V      W     W 

3.      W     W     V

4.      V       W     V     V

5.      W       V     W

6.      W       V     V      V

7.      V        V     W     V

8.      V        V      V     W

      The problem here is that for n 'V's,how many ways do we have to treat it?Because the answer may be too large, you should output the answer module by p.(If  n is 0,then we have just one way.)

输入

There are multiple test cases. The first line of the input contains an integer M, meaning the number of the test cases.
For each test cases, there are two integers n and p in a single line.
You can assume that 0<=n<=2100000000, 0<p<=2009.

输出

For each test case, output the answer with case number in a single line.

样例输入 复制

2
5 5
4 7

样例输出 复制

3
5

来源/分类