## LCC/Moose '19 Contest 5 S5 - Caterpillar

View as PDF

Points: 20 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type

For some integers , define the "caterpillar sum" to be the following sum:

For example, the caterpillar sum for is .

Your task is to evaluate the caterpillar sum for various values of , and .

#### Input Specification

The input begins with an integer , the number of test cases. lines follow, each containing three integers .

For at least 30 points, and .

#### Output Specification

For each test case, output the caterpillar sum of , modulo .

#### Sample Input 1

3
5 3 1
10 1 1
10 10 1

#### Sample Output 1

90
55
3628800