This page is still under construction.

Parts of this page are still being built. What you see may change.

Knights

Time limit60sMemory limit256 MB

Summary
Count non-attacking knight placements on an M by N board with M up to 4 and N up to 1e9, modulo 1000000009.
Level

Medium7 of 10

Topics
Dynamic programming, Matrix, Bit manipulation
Solved
No attempts yet

Problem

You place knights on a chessboard with MM rows and NN columns. Each square holds at most one knight.

No two knights on the board may attack each other. A knight attacks the square reached by moving two squares in one direction and then one square perpendicular to that direction. In the picture below, the squares attacked by the knight in the center are marked with X.

The squares a knight attacks

Given the size of the board, write a program that counts the ways to place the knights. Placing no knight at all counts as one way.

Input

The first line contains the number of test cases TT. (1≤T≤101 \le T \le 10)

Each of the next TT lines contains one test case: two integers MM and NN, separated by a space, giving the size of the board. (1≤M≤41 \le M \le 4, 1≤N≤1091 \le N \le 10^9)

Output

For each test case, print the number of ways to place the knights modulo 1,000,000,009 on its own line.

Examples1

  1. Example 1

    Input
    4
    1 2
    2 2
    3 2
    4 31415926
    
    Expected output
    4
    16
    36
    413011760