Boring Factorials#5405

Boring Factorials

1 second
128 megabytes
Easy

Given a prime number and an integer . Compute the value of n! \bmod p.

Input

The first line contains the number of queries t~(1 \le t \le 1000).

Each of the following lines contains two integers n~(1 \le n \le 2 \cdot 10^9) and p~(1 < p \le 2 \cdot 10^9), where is a prime number. It is known that |n - p| \le 1000.

Output

For each query, output the value of n! \bmod p on a separate line.

Examples

Example 1

Loading
Loading