Under construction

Still being built. Things may change

Domino Covering

Time limit6sMemory limit512 MB

Summary
Count the domino tilings of an n by m grid for up to 20000 queries, with n at most 35, m up to 10^18, and a prime modulus p given per query.
Level

Hard9 of 10

Topics
Matrix, Dynamic programming, Divide and conquer, Math
Solved
No attempts yet

Statement

Elizur has an empty n×mn \times m grid. He wants to cover the whole grid with some 1×21 \times 2 and 2×12 \times 1 dominoes. Each domino covers exactly two adjacent squares, and each square is covered by exactly one domino. Two squares are adjacent if they share a side.

The grid can be covered if and only if at least one of nn and mm is even. Otherwise, some square must always be left empty. He wants to know how many ways there are to cover the entire grid. Two coverings are different if there exist a domino from one covering and a domino from the other such that they cover the same square in one place but cover different squares elsewhere.

The answer can be very large, so output it modulo a prime pp.

Input

The first line contains one integer TT (1≤T≤200001 \le T \le 20000), the number of queries.

Each of the next TT lines contains three integers nn (1≤n≤351 \le n \le 35), mm (1≤m≤10181 \le m \le 10^{18}), and pp (2≤p≤2302 \le p \le 2^{30}, pp is prime).

At most 1000 queries satisfy n>5n > 5 or m>109m > 10^9.

Output

For each query, output one line containing the number of covering ways modulo pp.

Hint

The figure shows all 11 possible coverings of a 3×43 \times 4 grid.

Examples1

  1. Example 1

    Input
    6
    2 2 23
    2 3 233
    3 3 2333
    3 4 23333
    4 4 2332333
    5 251346744251346744 998244353
    
    Expected output
    2
    3
    0
    11
    36
    295381485