1756: Garden visiting

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

题目描述

There is a very big garden at Raven’s residence. We regard the garden as an n*m rectangle. Raven’s house is at the top left corner, and the exit of the garden is at the bottom right. He can choose to take one step to only one direction (up, down, left or right) each time. Raven wants to go out of the garden as quickly as possible, so he wonders how many routes he could choose. Raven knows there are many possible routes, so he only wants to know the number, which is the result that the total number of possible routes modes a given value p. He knows it is a simple question, so he hopes you may help him to solve it.

输入

The first line of the input contains an integer T, which indicates the number of test cases. Then it is followed by three positive integers n, m and p ( 1 <= n, m, p <= 10^5 ), showing the length and width of the garden and p to be the mod of the result.

输出

For each case, output one number to show the result (the sum modes p).

样例输入 复制

3
2 2 5
2 6 16
6 6 24

样例输出 复制

2
6
12

提示

Sample 1: There are 2 routes in total. Sample 2: There are 6 routes in total. Sample 3: There are 252 routes in total.